How to use cURL through a Proxy Server in PHP

Donnerstag, 31.03.2011 | PHP | Keine Kommentare | php , proxy server , curl

Many companies allow access to the Internet through a Proxy Server, only. That makes it hard to developers to download files with standard features. One way is to use cURL. It's possible to setup cURL to use a Proxy Server.

In PHP it looks like this:

$res = curl_init();  
curl_setopt($res, CURLOPT_URL, 'http://www.someurl.com/');  
curl_setopt($res, CURLOPT_RETURNTRANSFER, 1);  
curl_setopt($res, CURLOPT_PROXY, '192.168.10.1:8080');  
curl_setopt($res, CURLOPT_PROXYUSERPWD,'user:pass');  
$string = curl_exec($res);  
curl_close($res); 

Share