PHP CURL 请求302跳转页面

<?php
$url = 'http://www.bingdou.net/';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//若给定url自动跳转到新的url,有了下面参数可自动获取新url内容:302跳转
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//设置cURL允许执行的最长秒数。
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0');
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$content = curl_exec($ch);
//获取请求返回码,请求成功返回200
$code = curl_getinfo($ch,CURLINFO_HTTP_CODE);
echo $code . "\n\n";

//获取一个cURL连接资源句柄的信息。
//$headers 中包含跳转的url路径 
$headers = curl_getinfo($ch);
var_dump($headers);

0

评论0

请先

没有账号? 注册  忘记密码?

社交账号快速登录