PHP

This article provides an example of using a proxy to make an HTTP request with the PHP programming language.

PHP Code

In this example, we use the Residential proxy below:

residential.pingproxies.com:7777:customer-tt_pp_lz_5051-sessid-Z9tCGVYHu:23n22mk22

This proxy is split into four parts separated by colons. We first save the proxy as a string variable, then split it into four parts at each colon (:) and then add it, with authentication, to our proxy dictionary.

$proxy_string = "residential.pingproxies.com:7777:customer-tt_pp_lz_5051-sessid-Z9tCGVYHu:23n22mk22";
$proxy_parts = explode(":", $proxy_string);
$ip_address = $proxy_parts[0];
$port = $proxy_parts[1];
$username = $proxy_parts[2];
$password = $proxy_parts[3];
$url = "http://www.google.com/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, $port);
curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTP');
curl_setopt($ch, CURLOPT_PROXY, $ip_address);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $username.':'.$password);
$data = curl_exec($ch);
curl_close($ch);
echo $data;

Last updated