How to Use HTTP Proxies in PHP Code
Using HTTP proxies in PHP is simple as long as the cURL library is enabled on your server. Below is a quick guide on how to set it up with HighProxies.
Step 1: Create a Test PHP File
Create a file named test.php and add the following code:
<?php
$proxy = '154.30.208.20:21264'; // Replace with your PROXY_IP:PROXY_PORT
$url = 'https://www.google.com';
$content = getUrlContents($url, $proxy);
print $content;
function getUrlContents($url, $proxy = null, $post_data = null, $timeout = 30, $userpass = null) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
if ($post_data !== null) {
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
}
if ($proxy !== null) {
curl_setopt($curl, CURLOPT_PROXY, $proxy);
}
if ($userpass !== null) {
curl_setopt($curl, CURLOPT_USERPWD, $userpass);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($curl, CURLOPT_MAXREDIRS, 5);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
$contents = curl_exec($curl);
curl_close($curl);
return $contents;
}
?>
Tip: Replace 154.30.208.20:21264
with your HighProxies IP and Port. If your proxy requires authentication, pass your username and password via the $userpass
parameter.
Step 2: Upload and Run the File
- Upload
test.php
to your server. - Open it in your browser (example:
https://yourdomain.com/test.php
).
Possible Results
- Success: You’ll see the HTML content of the target URL.
- Access Denied: Ensure your server’s IP is authorized in the HighProxies control panel.
- cURL Error: Check with your hosting provider to confirm cURL support is enabled.
Why Use HTTP Proxies with PHP?
- Access geo-restricted content
- Add privacy and security to your requests
- Improve efficiency for scraping or automation projects
- Manage multiple requests with different IPs
With HighProxies, you can integrate proxies into your PHP projects easily — ensuring fast, secure, and anonymous connections.