PHP curl with proxy

PHP curl with proxy:

The following information will teach you how to use curl function behind a proxy. Below is the 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://example.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);

0 comments:

Post a Comment

+