Using your FoxyProxy Account with PHP

  1. Home
  2. Programmatically accessing your Proxy
  3. Using your FoxyProxy Account with PHP

Here’s a code snippet that uses your FoxyProxy account with PHP.

Although this example uses the HTTP proxy server on port 3128, other ports are available (usually 13129) with your account. HTTPS proxy server access is also available on the same ports, which encrypts traffic between your client and FoxyProxy proxy servers. Your account also comes with SOCKS5 proxy server access, typically on port 21. You can find this information by logging into your account at the Control Panel.

$ch=curl_init();

/* Simulate Chrome 41.0.2228.0 on OSX */
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");

/* Port is typically 3128 or 13129 for HTTP/HTTPS and 21 for SOCKS5. Check your account info at https://getfoxyproxy.org/panel */
curl_setopt($ch, CURLOPT_PROXY, "$SERVERNAME:$PORT");

/* Can also use CURLPROXY_SOCKS5 or CURLPROXY_SOCKS5_HOSTNAME for CURLOPT_PROXYTYPE */
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);

/* Your FoxyProxy account username and password */
curl_setopt($ch, CURLOPT_PROXYUSERPWD, "$USER:$PASS");

curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_URL, "http://google.com/");
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;

The output of this code is the response to calling http://google.com/

Related Articles