Re: cURL & cookies

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

 



On Sat, April 22, 2006 3:12 am, Peter Hoskin wrote:
> I'm trying to produce an sms sending script, however having problems
> with curl and storing cookies. The login page works fine, however the
> second http request returns a login page rather than authenticated
> content. Additionally, in the headers a different cookie value for
> JSESSIONID is set.
>
> I'm running PHP/5.1.2 on FreeBSD
>
> This script:
> define('COOKIEJAR','/path/to/curl-cookiejar');
> define('USERAGENT','Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
> 5.1)');
>
>
> $ch = curl_init();
> curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);
.
.
.
> $return['login'] = curl_exec($ch);
> curl_close($ch);
> unset($ch);
>
> $ch = curl_init();
> curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR);

Here,  you should also use CURLOPT_COOKIEJAR and COOKIEJAR, in case
you get some *MORE* cookies on subsequendc pages.

In fact, go ahead and just use both options all the time -- assuming
your COOKIEFILE starts off empty.

Or perhaps you should http://php.net/unlink it at the beginning.

> $fp = fopen(COOKIEJAR,'w');
> fclose($fp);

Ah.

This is to wipe out the COOKIEJAR when you're done, right?...

If not, get rid of it.

Oh, and here's the REAL problem:

If you use CURLOPT_HEADER, 1, then, like, for some reason beyond my
ken, the COOKIEJAR/COOOKIEFILE stuff just plain doesn't get done.

This really sucks if you need *other* headers and want curl to manage
the Cookies for you, but there it is.

I'm not sure if I remembered to file a bug report on that or not...

If the general conscensus on this list is that CURLOPT_HEADER "on"
should not negate the use of CURLOPT_COOKIEFILE and/or
CURLOPT_COOKIEJAR, then we may want to file a bug report...

But I strongly suspect that bug report would most correctly go to
curl, and not PHP, since I doubt that PHP does anything to screw this
up -- it's probably all in curl itself, no?

Or maybe me and Peter are the only 2 guys on the planet that think you
should get to have both...

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
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