$matches, "body" => $body, "header" => $header, 'code' => curl_getinfo($ch, CURLINFO_HTTP_CODE) ]; curl_close($ch); return $ret; } $ret = curl_exec($ch); if (@$paras['loadurl']) { $Headers = curl_getinfo($ch); $ret = $Headers['redirect_url']; } curl_close($ch); return $ret; } function Rand_IP(){ #第一种方法,直接生成 $ip2id= round(rand(600000, 2550000) / 10000); $ip3id= round(rand(600000, 2550000) / 10000); $ip4id= round(rand(600000, 2550000) / 10000); #第二种方法,随机抽取 $arr_1 = array("218","218","66","66","218","218","60","60","202","204","66","66","66","59","61","60","222","221","66","59","60","60","66","218","218","62","63","64","66","66","122","211"); $randarr= mt_rand(0,count($arr_1)-1); $ip1id = $arr_1[$randarr]; return $ip1id.".".$ip2id.".".$ip3id.".".$ip4id; } #获取重定向请求头 function getResponseHeader($url) { $ch = curl_init($url); $httpheader = []; $httpheader[] = 'X-FORWARDED-FOR:'.Rand_IP(); $httpheader[] = 'CLIENT-IP:'.Rand_IP(); #请求头中添加cookie $httpheader[] = 'cookie:did=web_'.md5(time() . mt_rand(1,1000000)).'; didv='.time().'000;clientid=3; client_key=6589'.rand(1000, 9999); curl_setopt($ch, CURLOPT_HTTPHEADER,$httpheader); #以下两句设置返回响应头不返回响应体 curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_NOBODY, true); #返回数据不直接输出 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $content = curl_exec($ch); curl_close($ch); return $content; } #获取响应体 function getResponseBody($url) { $ch = curl_init(); #5秒超时 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5000); #设置默认ua 这里经常测试,尽量用手机的ua,电脑的ua获取不到数据 curl_setopt($ch, CURLOPT_USERAGENT,'User-Agent: Mozilla/5.0 (Linux; Android 5.1.1; vivo X9 Plus Build/LMY48Z) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36'); #把随机ip添加进请求头 $httpheader = []; $httpheader[] = 'X-FORWARDED-FOR:'.Rand_IP(); $httpheader[] = 'CLIENT-IP:'.Rand_IP(); #请求头中添加cookie $httpheader[] = 'cookie:did=web_'.md5(time() . mt_rand(1,1000000)).'; didv='.time().'000;'; curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader); #返回数据不直接输出 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); #设置请求地址 curl_setopt($ch, CURLOPT_URL, $url); #关闭ssl验证 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); #设置默认referer curl_setopt($ch, CURLOPT_REFERER, 'https://www.moestack.com'); #get方式请求 curl_setopt($ch, CURLOPT_POST, false); $contents = curl_exec($ch); curl_close($ch); return $contents; }