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:

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 = "";
$proxy_parts = explode(":", $proxy_string);
$ip_address = $proxy_parts[0];
$port = $proxy_parts[1];
$username = $proxy_parts[2];
$password = $proxy_parts[3];
$url = "";
$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);
echo $data;

Last updated