0

When I get a response from a page, it gives a response data but if I want to get cookie of the session which is set by page, how can I get it with PHP cURL?

Amal Murali
  • 75,622
  • 18
  • 128
  • 150
  • `curl_setopt($ch,CURLOPT_COOKIEJAR,'cookies.txt'); curl_setopt($ch,CURLOPT_COOKIEFILE,'cookies.txt');` – Eugen Jan 05 '14 at 09:47
  • may help this http://stackoverflow.com/questions/247006/save-cookies-for-remote-web-pages – Akhil P M Jan 05 '14 at 09:52

1 Answers1

2

There are two ways(may be more) you can do this.

Using the cookie file:

$cookie_file = 'e:/demo/cookies.txt';
curl_setopt($ch,CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch,CURLOPT_COOKIEFILE, $cookie_file);

Using from the header that is responded back with html source from curl.

curl_setopt($curl_connection, CURLOPT_HEADER, true);
// this is returning the http response header along with html

You'll find the cookies there under the Set-Cookie: header for second example.

By the way, I assume you know how to handle curl. If you don't here are few helps.

Sabuj Hassan
  • 38,281
  • 14
  • 75
  • 85