Connect Remote Servers using Curl with Proxy

Connect Remote Servers using Curl with Proxy

Using curl to Connect Remote Servers

Curl and proxies

As with all other full featured browsers curl has support for proxies. Proxy

servers are buffers between the requesting client and the web server. Proxy

servers are used for a variety of reasons including companies restricting web

access to people wanting to appear anonymous.

There are a few curl options to set when using a proxy. First to enable use of a

proxy in curl use the option CURLOPT_HTTPPROXYTUNNEL. Second set

the proxy with the option CURLOPT_PROXY. If you need to set

authentication information use the option CURLOPT_PROXYUSERPWD.

CURLOPT_PROXYUSERPWD expects a string in the format of

user:password. HTTP proxies are default, to use a SOCKS proxy use the

CURLOPT_PROXYTYPE option.

Example:

$ch = curl_init();
curl_setopt($ch, CURLOPT_PROXY, ‘proxyname or no:portno’);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, ‘user:password’);
curl_setopt($ch, CURLOPT_URL, ‘http://www.sample.com’);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec();
curl_close($ch);

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.