0

I need to access a website from php with curl, but I must use a proxy.

Is there a simple way to set curl to use a proxy?

If there is no simple way, what other options are available?

Please supply a code example

Elia Weiss
  • 8,324
  • 13
  • 70
  • 110

1 Answers1

1

Did you searched already on stackoverflow? You might check this answer How to use CURL via a proxy?

Or doesn't answer this your question?

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.foo.bar');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_NTLM);
curl_setopt($ch, CURLOPT_PROXY, 'proxy:8080');    
curl_setopt($ch, CURLOPT_PROXYPORT, 8080);    
curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'domain\user:password');    

curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch, CURLOPT_REFERER, 'http://myreferer.com');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla...');

$result = curl_exec($ch);
$info = curl_getinfo($ch);
$error = curl_error($ch);

curl_close($ch);
Community
  • 1
  • 1
rogaa
  • 370
  • 2
  • 16