时间:2021-07-01 10:21:17 帮助过:17人阅读
$header[] = 'Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, text/html, * ' . '/* '; $header[] = 'Accept-Language: zh-cn '; $header[] = "User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0"; $ch = curl_init(); //初始化curl //允许curl提交后,网页重定向 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //将curl提交后的header返回 curl_setopt($ch, CURLOPT_HEADER, 1); //递归抓取LOCATION curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //以上处理重定向 curl_setopt($ch, CURLOPT_URL, $url); //设置链接 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); //HTTPS必须设置不验证 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); //HTTPS必须设置不验证 curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); //设置是否返回信息 curl_setopt($ch, CURLOPT_HTTPHEADER, $header); //设置HTTP头$html = curl_exec($ch); //接收返回信息 curl_close($ch);
以上就介绍了一段phpcurl代码,包括了网页重定向方面的内容,希望对PHP教程有兴趣的朋友有所帮助。