alwaysLearn
alwaysLearn

Reputation: 6950

Sending cookie values in php curl

I haved logined to the site using curl and at that time I am saving the cookies in some file 'abc.txt'.

Now to proceed further I want to read the cookies that I have saved in 'abc.txt' and send them to other page of same site.

How can I do that in PHP .. Please suggest.

Thanks in advance.

Upvotes: 0

Views: 723

Answers (1)

user142162
user142162

Reputation:

You need to set the CURLOPT_COOKIEFILE option in your cURL resource:

$cookie_file = 'abc.txt';
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_file);

From the documentation:

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. If the name is an empty string, no cookies are loaded, but cookie handling is still enabled.

If you want cURL to dump cookies to a file after it has completed processing a URL, then you need to set the CURLOPT_COOKIEJAR option:

curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_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: 1

Related Questions