cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Retrieving cookies

From: Adam Bodnar <adambodnar_at_mac.com>
Date: Wed, 21 Apr 2004 18:41:12 -0500

I'm very new to Curl, but figuring it out pretty quickly.

A problem I'm running into is that I need to retrieve a cookie that is
set by the page after I do a Curl POST submit to it.

Now I've read thru all the documentation and all I found was mention of
CURLOPT_COOKIEFILE and then some examples with CURLOPT_COOKIEJAR. Now
the former seems to be entirely related to sending a file with the
cookie information you want to pass to a Curl session and the latter
seems to be something where you can store the cookies(despite the lack
of documentation on this on the PHP site).

I would prefer that I could set a variable to the cookie(s), but from a
bug I read on the PHP site, it seems this is not possible yet.

So I messed around with this a bit and with the intention that any
cookie information would be written to the
filename(/tmp/my_cookies.txt) I sent CURLOPT_COOKIEJAR to so I then
could read the information out of the file. However, the file was never
written.

curl_setopt($ch2, CURLOPT_COOKIEJAR, "/tmp/my_cookies.txt");
curl_setopt($ch2, CURLOPT_COOKIEFILE, "/tmp/my_cookies.txt");

It seems the only way I can grab the cookies that are set by the page
would be write a regular expression to parse the header information
that is returned by the curl_exec cmd.

So in all,

1) Is there no way to get the cookie information that is set by a curl
session into a variable?
2) If 1 is not possible, can you write it to a file? If so, then what
am I doing wrong.
3) If 1 and 2 aren't possible or it makes sense, should I just parse
the header information?

Thanks for the help,

Adam Bodnar
Received on 2004-04-22