2

I am setting/storing CURL cookies with :

curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);

And retrieving them / trying to set them in my browser with:

 setcookie($cookie);

But what goes inbetween please?

Cookie variable defining looks like:

`$cookie="cookie.txt"`;

Is there some way to parse the cookie file as an array?

TV watcher
  • 21
  • 4

2 Answers2

0

I can't find any official library that can do it for you.

This question has script to parse cookie file. Pay attention to answer about HttpOnly.

Or you might want to parse cookies directly from curl response. Then check this question.

Community
  • 1
  • 1
vl.lapikov
  • 756
  • 7
  • 12
0

this is the way i done it

$cookies = [];
$lines = file($cookiesFile);
foreach($lines as $line) {
            if($line[0] !== '#' && $line[0] !== "\n") {
                $tokens = explode("\t", $line);
                $cookies[$tokens[5]] = trim($tokens[6]);
            }
        }
Or Cohen
  • 1
  • 1