0

There is a website that I'm logged in , So there are cookies saved on my browser , I want to get these cookies.

I have tried CURL:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);

//Save Cookies To cookie.txt .
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");

//Use Cookie Saved In cookie.txt .
curl_setopt($curl, CURLOPT_COOKIEFILE,"cookie.txt");

curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:11.0) Gecko/20100101 Firefox/11.0');
curl_setopt($ch, CURLOPT_HEADER  ,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER  ,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION  ,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$content = curl_exec($ch);
curl_close($ch);

But it doesn't work.

In the cookie.txt there is text like:

#HttpOnly_.website.com  TRUE    /   TRUE    1681336501  gt_ab   rn:ODUy
#HttpOnly_.website.com  TRUE    /   TRUE    1681336501  gt_p    id:Y2YxNDM3YjUtYjdlNC00YTc2LWE4ZjctYjFiOThkMWQ5NGZi

So is there is a way to make it work I get the cookies?

Spoody
  • 2,804
  • 1
  • 25
  • 35
  • You don't like the values in `cookie.txt` or what? – Spoody Apr 13 '18 at 22:00
  • @MehdiBounya , I think they are not the real cookies , Because when I use `curl_setopt($curl, CURLOPT_COOKIEFILE,"cookie.txt");` , It doesn't work. –  Apr 13 '18 at 22:01
  • 1
    you can only access a cookie from the domain that 'created' that cookie. _BUT_: you say it's your browser. So why don't you just get either the file (depends on browser where to find it) or use the debug-tools to get the (local) cookie? – Jeff Apr 13 '18 at 22:02
  • @Jeff , There are extensions and browser tools , But I would like to make it programmatically if it's possible. –  Apr 13 '18 at 22:11
  • Then it has to be local, not via http. You can only get cookies via http if you created them before - from the same domain. Anything else would be a major security hack. – Jeff Apr 13 '18 at 22:15
  • Then I suggest using your local filesystem to get the files. (if you have php running local) – Jeff Apr 13 '18 at 22:15
  • @Steve Cookies are in the browser's memory, they're not on the web site. Every client gets its own cookies, so the cookies in `curl` are not the same as the cookies in the browser. – Barmar Apr 13 '18 at 22:24
  • The only way to get the cookies in the browser is to use its tools, there's no general purpose way to do it. – Barmar Apr 13 '18 at 22:25

1 Answers1

0

The line :

curl_setopt($ch, CURLOPT_HEADER ,1);

cause the curl_exec function to get both header and body of the response.

this link might help:

how to get the cookies from a php curl into a variable

good luck