Este sitio web utiliza cookies para realizar análisis y mediciones de tus visitas. [ Acepto ] [ Más información aquí ].

How to use a Proxy in PHP

Learn how to use a proxy in PHP to hide the activity of any script running on external websites. Hide the IP address of your PHP script. Anonymize your scrapers, parsers or crawlers, and avoid the annoying captchas. In the following code, replace the IP and port in bold letters with your own IP and port. In HideMyAss you can find a list of free frequently updated IP addresses. Try with many, since some work for a very short period of time.

When the get_data function runs, all the content of the visited webpage will be stored inside the variable $data.

function get_data($url) {

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,$url);

curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 0);

curl_setopt($ch, CURLOPT_PROXY, '117.59.217.236:80');

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'GET');

curl_setopt ($ch, CURLOPT_HEADER, 1);

$data = curl_exec ($ch);

$curl_info = curl_getinfo($ch);

print_r($curl_info);

curl_close($ch);

return $data;

}

$data = get_data("http://www.idealista.com");

There are different ways to use a proxy at the fifth line:

$proxies[] = 'user:password@173.234.11.134:54253'; // user, password, IP address and port

$proxies[] = '173.234.92.107'; // only IP address

$proxies[] = '173.234.94.90:54253'; // IP address and port

Añadir comentario