Re: cURL: can't prevent url redirect

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, November 29, 2006 11:26 pm, Andrew Warner wrote:
> Actually, the problem is that the site isn't recognizing my cookies.
> Is there anything wrong with the below code? Same thing in Snoopy
> works perfectly. Going to stick with Snoopy.
>
> $the_headers = array(
>     "Language: en",
>     "Accept: */*",
>     "User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en)
> AppleWebKit/418.9 (KHTML, like Gecko) Safari/419.3",
>     "Content-type: text/html"
> );
>
>
> $restored_cookies = restore_cookies ();
>
>
> foreach($restored_cookies as $name=>$value)
>       array_push($the_headers, "Cookie: ".$name.'='.$value);
>
> // headers look good:
> echo '<pre>'; print_r($the_headers); echo '</pre>';
>
> $ch = curl_init($url);
> curl_setopt($ch, CURLOPT_HTTPHEADER, $the_headers);
> curl_setopt($ch, CURLOPT_HEADER, 0);
> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
> $response = curl_exec($ch);
> curl_close($ch);

If you don't need any other headers, you can just use curl's
COOKIE_FILE and COOKIE_JAR, both pointing to the same file on your
server, which PHP must be able to read/write.

curl will maintain all the cookies for you.

If you *do* need other headers, then you need to do all this stuff
you're doing to both maintain the cookies and get the headers, as, at
least in my experience, you can't convince curl to both give you the
headers and to use the COOKIE_JAR :-(

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux