Phpcurl is accessed by proxy. the server can. if it is not tested locally, use the & nbsp; curl proxy for access. the test is feasible on the server, but the result is blank on the local server. ask what the situation is, the proxy ip address is found online. function & nbsp; curl_string & nbsp; ($ url, $ user_agent, $ proxy) {& nbsp; & nbsp; & nb php curl can be accessed by proxy on the server, but cannot be accessed locally
The test uses a curl proxy for access. the test is feasible on the server, but the result is blank on the local device. for details, refer to the situation where the proxy ip is found online and available.
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;
------ Solution ----------------------
111.13.109.53 Beijing Mobile
Ping failure
Access http: // 111.13.109.53: 80 does not exist
Apparently a protected ip address
------ Solution ----------------------
The proxy ip cannot be pinged. how can you access Baidu based on the proxy?