cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: Curl and cookies

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Sat, 2 Feb 2008 15:52:44 +0100 (CET)

On Sat, 2 Feb 2008, Tig wrote:

> The site is set so that I first need to log on before I can get the data; so
> I use following code to create cookie files and then I get my data using the
> second code.
>
> Code 1
> ---------------------
> $c = `\"$dir\"/curl/curl.exe -s -A "Mozilla/4.0" -c cookies.txt -d
> "usrname=xxx&uemail=xxx\@xxx.be&peeword=xxxx&submit=Login"
> www.somewebsite.com/login.php`;
> ---------------------
>
> Code 2
> ---------------------
> $cont = `\"$dir\"/curl/curl.exe -s -S -A "Mozilla/4.0" -b cookies.txt
> www.somewebsite.com/somefile.php?jump=$i`;
> ---------------------

This second snippet assumes that the cookies remain the same, which seems like
an unnecessary restriction and one possible reason for your problem. I'd
recommend using -c for the "code 2" case as well.

> That $i is the pagenumber to get the data from ... this all runs in a loop
> ($i = 1 to 10)
>
> I did find on the internet that you can work with comma seperated lists (for
> example {1,2,3,4,5,6,7,8,910} of [1-10] instead of that $i; but that doesn't
> seem to work ...

It works with all somewhat modern curl versions, but of course you need to put
the URL within quotes so that the shell doesn't mess up the []-letters.

> I there a way to make the cookiefile stay alife longer than for 1 page
> visit, so I can set the cookiefile creation code outside the loop; making
> the script much faster?

The cookiefile is just the cookies, there's no particular thing you can or
should do to make the cookies magically live longer. They live as long as the
server told your client, at least as long as the time on your client is
reasonable correct. But as I mentioned already, it is quite possible that one
or more cookies should be updated as you go along.

-- 
  Commercial curl and libcurl Technical Support: http://haxx.se/curl.html
Received on 2008-02-02