cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Cookies..

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Mon, 16 Sep 2002 09:36:55 +0200 (MET DST)

On Fri, 13 Sep 2002, Lorenzo Pastrana wrote:

> > 1. you create a cookiejar to store incoming cookies in.
> > curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookieFileName");
>
> Does this file needs to exist already, or curl will create it on the fly?

libcurl will create it if it doesn't exist, and overwrite it if does exist.

> > if you then look in /tmp/cookieFileName you will see the cookies that you
> > were given by the www.myterminal.com
>
> well, I can't see nothing there... :( Is there any special condition to be
> matched for the cookiejar is created ?

The file is only written when you *cleanup() the handle. Until then, the
cookies are kept in memory only.

> Actually I'm reusing the handles for multiple urls so I won't call
> curl_easy_cleanup between them, is that the reason ? If it is, how can I
> use cookies and persistant connections at the same time ?

The cookies are used when CURLOPT_COOKIEJAR is set, it just doesn't create
the file until you cleanup.

> Is there a way to force the cookie dump other than curl_easy_cleanup ?

No. I don't see the point in doing that.

> > 5. if you want to use these cookies to go futher around the site you use
> > curl_setopt($ch1, CURLOPT_COOKIEFILE, "/tmp/cookieFileName");
>
> What I can't figure out here is : how the cookiejar mechanism would consider
> the file

COOKIEJAR is for saving cookies, COOKIEFILE for reading them.

> will it be erased before saving so I need a single file per url (witch is
> not a problem BTW, and I suspect it is the correct procedure anyway..) or
> can I give the same file for every url and proper management will be done ?

Since you don't cleanup at all, you don't have to care about the file at all
between separate URLs. But otherwise, in case you do cleanup, use COOKIEFILE
to read it again and use COOKIEJAR to write it. You can very well use the
same file over and over, yes.

> Also, are CURLOPT_COOKIEFILE and CURLOPT_COOKIEJAR compatibles on a same
> handle so I can feed the server with already stored cookies and eventually
> keep track of any possible update / addition ?

They are.

-- 
 Daniel Stenberg -- curl related mails on curl related mailing lists please
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
Received on 2002-09-16