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); 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; }
|