Search

Saturday, October 11, 2008

CURL and Proxy Support

CURL has support for proxies, including SSL. Below we refer to the code snippet in the first example, but modify it to use a proxy.

[php] // Initialize the CURL library
$cURL = curl_init();

// Set the URL to execute
curl_setopt($cURL, CURLOPT_URL, "http://www.google.com");

// Set options
curl_setopt($cURL, CURLOPT_HEADER, 1);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cCURL, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($cCURL, CURLOPT_PROXY, "myproxy.com:1080");
curl_setopt($cCURL, CURLOPT_PROXYUSERPWD, "mysuername:mypassword");

// Execute, saving results in a variable
$strPage = curl_exec($cURL);

// Close CURL resource
curl_close($cURL);

// This will print out the HTML contents
echo($strPage);
?>[/php]


source : http://www.codeandcoffee.com

No comments: