Using your Proxy Account with PHP

From FoxyProxy Documentation
Revision as of 04:21, 2 December 2015 by Ejung (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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;