$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教程有兴趣的朋友有所帮助。