GETting url content via proxy in cURL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

GETting url content via proxy in cURL

Post by anjanesh »

Code: Select all

$handle = curl_init();

curl_setopt ($handle, CURLOPT_HEADER, TRUE);
curl_setopt ($handle, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1");
curl_setopt ($handle, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt ($handle, CURLOPT_REFERER, "");
curl_setopt ($handle, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt ($handle, CURLOPT_MAXREDIRS, 5);
curl_setopt ($handle, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt ($handle, CURLOPT_FAILONERROR, TRUE);
curl_setopt ($handle, CURLOPT_COOKIESESSION, TRUE);
curl_setopt ($handle, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt ($handle, CURLOPT_COOKIEJAR,  "cookie.txt");
curl_setopt ($handle, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt ($handle, CURLOPT_PROXY, "http://202.150.105.35:1080");

$url = "http://yahoo.com";

curl_setopt ($handle, CURLOPT_URL, $url);
$file_contents = curl_exec($handle); $ErrNo = curl_errno($handle);

if ($ErrNo != 0) echo "Error : $ErrNo : ".curl_error($handle);
echo $file_contents;

curl_close($handle);
I always get Error : 28 : connect() timed out! or Error : 7 : couldn't connect to host

Any idea why ?

Thanks
Post Reply