用法:

1
2
3
4
5
6
c_get(URL,method(post/get),data,referer,timeout(second),use_cookie(true/false),save_cookie(true/false),cookie_Path)
return:
$content = array(
$body,
$header
);

例如:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//POST METHOD :D
c_get(
"https://localhost/testlogin.php",
'post',
array("name" => "username","pass" => "userpassword"),
"",
15,
false,//不传输cookie
true,//保存cookie
"testlogin.ck.txt"
);
//GET METHOD :D
$ct = c_get(
"https://localhost/testget.php?v1=val2333&v2=val1248",
'get',
"使用get的话,这里的data不用填,而是填到url那里去",
"https://www.referer.mother",
20,
true,//传输cookie
false,//不保存cookie
"ck/6zhen.txt"
);

复制以下代码:

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
44
45
46
function c_get($url, $method, $data = '', $referer = 'https://google.com/s', $timeout = 10, $useck = false, $saveck = false, $ckfile = "ck.txt") {
$headerinfo = array(
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/71.0.3578.80 Chrome/71.0.3578.80 Safari/537.36"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerinfo);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, $timeout * 1000); //超时毫秒 ms
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
if ($saveck == true) {
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
}
if (file_exists($ckfile) && $useck == true) {
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);
}
if ($method == "post") {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
$content = curl_exec($ch);
if (curl_errno($ch)) {
return 'Curl error: ' . curl_error($ch);
}
if ($content == false) {
return "Get content false!";
}
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($content, 0, $headerSize);
$body = substr($content, $headerSize);
if (in_array(curl_getinfo($ch, CURLINFO_HTTP_CODE), ['301','302'])) {
preg_match("@location: (.*?)[\n\r;]@i", $header, $tmpgo);
curl_close($ch);
return c_get($tmpgo[1]);
}
curl_close($ch);
$content = array(
$body,
$header
);
return $content;
}

By the way
CURLOPT_POSTFIELDS一定要在CURLOPT_POST之后设置,否则不能传输。