PHP

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

Friedrich Kräft avatar
Written by Friedrich Kräft
Updated over a week ago

PHP Code

In this example, we use the Residential proxy below:

resi.ipv6.plainproxies.com:8080:customer:product--resi6--pass--nicepass

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 = "resi.ipv6.plainproxies.com:8080:customer:product--resi6--pass--nicepass";
$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;

Did this answer your question?