PHP curl with proxy

Here is a simple PHP code snippet requesting given URL using curl and HTTP proxy server.

$loginpassw = 'login:password';  //your proxy login and password here
$proxy_ip = '127.0.0.1'; //proxy IP here
$proxy_port = 8080; //proxy port from your proxy list
$url = 'http://yahoo.com'; //URL to get

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0); // no headers in the output
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // output to variable
curl_setopt($ch, CURLOPT_PROXYPORT, $proxy_port);
curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTP');
curl_setopt($ch, CURLOPT_PROXY, $proxy_ip);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $loginpassw);
$data = curl_exec($ch);
curl_close($ch);

echo $data;

3 Responses to “PHP curl with proxy”

  1. jamith says:

    Hi, you provide excellent service! I’m using your proxies in combination with ruby scripts and the mechanize web scraping library. Maybe someone finds this interesting…

    http://pastie.org/745128

  2. SEO services says:

    I am not getting what is meant by curl php script. I need some more details how to use it.

  3. admin says:

    It’s simple. After executing the script you have the website (HTML source) from the $url variable in $data.

Leave a Reply