1.TIMEOUT值太小
2.建议增加CURLOPT_REFERER
3.USER AGENT最好不要从$_SERVER里面提取,它可以被客户端任意修改,也可能不存在,你的目的是从远程服务器获取数据,没有必要每次都去取访问你的网站的客户端的USER AGENT,只要发送一个不会被远程服务器拒绝的USER AGENT即可
4.最好先定义函数,再调用,这不算错误,但不是好习惯……
5.可以使用curl_getInfo()和curl_error()调试
6.你的代码我已经给你改好了……
function https_request($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$r = curl_exec($ch);
curl_close($ch);
return $r;
}
$jiekou='https://www.baifubao.com/callback?cmd=1059&callback=phone&phone=13457854758';
var_dump(https_request($jiekou));
?>