0

Why is it that when I grab a cookie and store it to a file, every line is FALSE/FALSE? I've tried various different ways and still end up with the same thing. What am I missing? And for a clarification, you load one url, it sets a cookie and bounces to another url where that cookie is then read. But I can't even get the cookie to set properly. Here's my code:

$cookie_file_path = 'cookie.txt';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url3);
curl_setopt($ch, CURLOPT_HEADER  ,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER  ,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
$content = curl_exec($ch);
curl_close( $ch );
echo $content;

EDIT: So my question is for this post - by receiving FALSE /FALSE - does that mean the cookie isn't set properly?

MrTechie
  • 1,797
  • 4
  • 20
  • 36

1 Answers1

0

See http://curl.haxx.se/mail/archive-2005-03/0099.html for a description of the format of the cookie.txt file. The columns are:

  • domain
  • tailmatch
  • path
  • secure
  • expires
  • name
  • value

tailmatch and secure are both booleans, so they're either TRUE or FALSE. So if you see:

www.domain.com FALSE / FALSE ...

it means:

  • tailmatch = FALSE
  • path = / means the cookie applies to all paths in the domain
  • secure = FALSE means the cookie doesn't require SSL

tailmatch is true when the cookie applies to all subdomains of a domain, rather than a specific hostname; the domain would then be .domain.com rather than something like www.domain.com.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • I'm not quite sure I understand. Does that mean it's not scrapable? – MrTechie May 19 '14 at 20:50
  • I never said that. You wanted to know why all the lines in the cookie file contain `FALSE / FALSE`. I explained what those mean. – Barmar May 19 '14 at 20:52
  • Are you saying that you don't get the other 4 columns, all you see is `FALSE / FALSE` on every line? I can't reproduce that with my URL. – Barmar May 19 '14 at 20:53
  • Ok, understood. Makes sense. But apparently I am doing something wrong, because it's not allowing me to capture the cookie correctly to be used for the next curl – MrTechie May 19 '14 at 20:53
  • here's an example: www.stuller.com FALSE / FALSE 1432060998 cart_session_id 6bfeb4a8-e993-44a9-b844-af3cc70dbff7 – MrTechie May 19 '14 at 20:53
  • So what's the problem? The name of that cookie is `cart_session_id`, and its values is `6bfeb4a8-e993-44a9-b844‌​-af3cc70dbff7`? The first `FALSE` means that the domain matched exactly, rather than matching the domain. The second `FALSE` means it's not SSL. – Barmar May 19 '14 at 20:58
  • The `/` means that the cookie applies to the root and all subdirectories of the server. – Barmar May 19 '14 at 20:58
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/53993/discussion-between-mrtechie-and-barmar). – MrTechie May 19 '14 at 21:10
  • Sorry Barmar, didn't mean to bring you into chat. – MrTechie May 19 '14 at 21:17
  • I hate when I accidentally click that, too. – Barmar May 19 '14 at 21:18
  • Here's my issue: http://stackoverflow.com/questions/23745468/curl-php-setting-cookies-properly – MrTechie May 19 '14 at 21:18