How to use a PROXY in cURL ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
stephane02
Forum Newbie
Posts: 2
Joined: Wed Dec 02, 2009 12:20 pm

How to use a PROXY in cURL ?

Post by stephane02 »

Hi,

I have a problem using a proxy in cURL. I am trying to use the code below and it does not work unless I put curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, 0); ( CURLOPT_HTTPPROXYTUNNEL set to 0 ). Can you help me ?

Code: Select all

 
        $proxy = "217.174.242.152:3128";
        $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, 'http://www.ip2location.com/'); 
    curl_setopt($ch, CURLOPT_HEADER, true); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
    curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
    curl_setopt ($ch, CURLOPT_PROXY,"$proxy");
    $data = curl_exec($ch); 
    curl_close($ch);
 
Thank you for helping.

Stephane
scheme
Forum Newbie
Posts: 1
Joined: Wed Dec 09, 2009 5:24 pm

Re: How to use a PROXY in cURL ?

Post by scheme »

> curl_setopt ($ch, CURLOPT_TIMEOUT, 20);
> curl_setopt ($ch, CURLOPT_PROXY, "24.44.68.212:5542");
> curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
> curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
> curl_setopt ($ch, CURLOPT_FAILONERROR, true);
> curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
stephane02
Forum Newbie
Posts: 2
Joined: Wed Dec 02, 2009 12:20 pm

Re: How to use a PROXY in cURL ?

Post by stephane02 »

Did you notice that it's giving a blank page ?
Post Reply