php curl 用代理訪問,伺服器可以,本地不行
測試用 curl代理訪問,在伺服器測試可行,本地卻顯示空白的,請教下是什麼情況,代理ip是網上找的,可用
function curl_string ($url,$user_agent,$proxy){
$ch = curl_init();
curl_setopt ($ch, CURLOPT_PROXY, $proxy);
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt ($ch, CURLOPT_COOKIEJAR, "c:\cookie.txt");
curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 120);
$result = curl_exec ($ch);
curl_close($ch);
return $result;
}
$url = "http://www.baidu.com";
$user_agent = "Mozilla/4.0";
$proxy = "http://111.13.109.53:80";
$string = curl_string($url,$user_agent,$proxy);
echo $string;
------解決思路----------------------
111.13.109.53 北京市 移動
ping 不通
訪問 http://111.13.109.53:80 報不存在
顯然是一個受保護的 ip
------解決思路----------------------
代理ip都ping不通你怎麼可能根據代理來訪問百度呢?