-
Notifications
You must be signed in to change notification settings - Fork 2
/
helper.php
43 lines (38 loc) · 926 Bytes
/
helper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?
$cookies = array();
function getCookies() {
global $cookies;
$res = "";
foreach ($cookies as $key => $cookie) {
$res .= "$key=$cookie; ";
}
return $res;
}
function saveCookies($r) {
global $cookies;
foreach ($r as $hdr) {
if (preg_match('/^Set-Cookie:\s*([^;]+)/', $hdr, $matches)) {
parse_str($matches[1], $tmp);
$cookies += $tmp;
}
}
}
function sendRequest($url, $data) {
$options = array(
'http'=>array(
'header' => "Cookie: ".getCookies() . "\r\nContent-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$obj = json_decode($result);
if ($obj->status == 'error') {
echo "There is an error: $obj->message";
exit;
}
saveCookies($http_response_header);
return $obj;
}
?>