How to use HTTP proxies in PHP code?

 

We support PHP code as long as the CURL library is enabled.

1. Create a file called test_proxy.php:

$proxy = '1.1.1.1:8800';  // <-- Replace 1.1.1.1:8800 with your proxy IP:PORT
$url = 'http://www.ipcheckit.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;
}

?>

2. Upload and navigate to test_proxy.php

-- If it works, you should see the contents of the specified $url

-- If you get an access denied page, ensure your server's IP is added as an authorized IP in our Control panel

-- If you see CURL errors, contact your web host about CURL support

  • 838 Users Found This Useful
Was this answer helpful?

Related Articles

Proxy Manager Guide

1.    Go to http://squidproxies.com/proxymanager/ProxyManager-v1.zip     2.    Save File,...

How to use a proxy in Chrome?

Click the Chrome menu on the  browser toolbar. Select Settings. Scroll down. Click "Show...

How to use a proxy in Firefox?

Go to Tools > OptionsClick on Advanced> Network > SettingsIn Connection Settings,...

How to use a proxy in Internet Explorer?

Go to Tools> Internet Options Click Connections > LAN Settings On Local Area Networn...

How to add my authorized IP?

To add your authorized IP, please go to : http://vip.squidproxies.com1. Login to the VIP control...

Powered by WHMCompleteSolution