stone
stone

Reputation: 841

CURL - cookies are stored where?

I would like to login to a site, so the first time I request a page, it redirects me to another page setting the cookies.

I am following a tutorial where they specify doing this

$cookie = '/tmp/cookies.txt';
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);

But when i check http live headers, the server passes cookie information to set my cookies. But i don't see it doing anything. When I examine the cookies, those values aren't there.

So do I have to specify another path for $cookie?

Upvotes: 1

Views: 4238

Answers (1)

Lekensteyn
Lekensteyn

Reputation: 66525

You've to use CURLOPT_COOKIEFILE for sending cookies instead of CURLOPT_COOKIE.

From the docs for function curl_setopt():

CURLOPT_COOKIE

The contents of the "Cookie: " header to be used in the HTTP request. Note that multiple cookies are separated with a semicolon followed by a space (e.g., "fruit=apple; colour=red")

CURLOPT_COOKIEFILE

The name of the file containing the cookie data. The cookie file can be in Netscape format, or just plain HTTP-style headers dumped into a file.

CURLOPT_COOKIEJAR

The name of a file to save all internal cookies to when the handle is closed, e.g. after a call to curl_close.

Upvotes: 4

Related Questions