Difference between revisions of "Using your Proxy Account with PHP"

From FoxyProxy Documentation
Jump to: navigation, search
(Created page with "Here is a PHP curl example. The output is an error code or the body of the HTTP(S) response made by the proxy server: <nowiki>$ch=curl_init(); curl_setopt($ch, CURLOPT_USERA...")
 
 
Line 1: Line 1:
Here is a PHP curl example. The output is an error code or the body of the HTTP(S) response made by the proxy server:
+
Here is a PHP curl example. The output is an error code or the body of the HTTP(S) response made by the proxy server (in this case, the IP address of the proxy server since http://icanhazip.com returns the IP address of the caller).
  
 
  <nowiki>$ch=curl_init();
 
  <nowiki>$ch=curl_init();
Line 9: Line 9:
 
curl_setopt($ch, CURLOPT_PROXYUSERPWD, "$USER:$PASS"); // Change to username:password provided to you by us
 
curl_setopt($ch, CURLOPT_PROXYUSERPWD, "$USER:$PASS"); // Change to username:password provided to you by us
 
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
 
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_URL, "https://icanhazip.com/"); // Change to the URL of the ultimate destination
+
curl_setopt($ch, CURLOPT_URL, "http://icanhazip.com/"); // Change to the URL of the ultimate destination
 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
 
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
 
curl_setopt($ch, CURLOPT_TIMEOUT, 30);

Latest revision as of 04:21, 2 December 2015

Here is a PHP curl example. The output is an error code or the body of the HTTP(S) response made by the proxy server (in this case, the IP address of the proxy server since http://icanhazip.com returns the IP address of the caller).

$ch=curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//	curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_PROXY, "$IP_OR_HOSTNAME:$PORT"); // Change to hostname.getfoxyproxy.org:port provided to you by us
curl_setopt($ch, CURLOPT_PROXYUSERPWD, "$USER:$PASS"); // Change to username:password provided to you by us
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_URL, "http://icanhazip.com/"); // Change to the URL of the ultimate destination
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_REFERER, "");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$result = curl_exec($ch);
curl_close($ch);
if ($result === FALSE)
  die("Error: " . curl_error($ch));
else
  echo $result;