CURLOPT_COOKIEJAR and CURLOPT_COOKIEFILE are simply utilities for processing cookies in a file, for example, in a web browser. And this is not recommended for your case.
But you can play directly with http headers to set and retrieve cookies.
To set cookies
<?php curl_setopt($ch, CURLOPT_COOKIE, 'user=xxxxxxxx-xxxxxxxx'); ?>
To receive cookies, simply specify headers that start with Set-Cookie:
You can check this document to understand how cookie headers work http://curl.haxx.se/rfc/cookie_spec.html
A use case, quick and dirty, but definitely not standard .
With these headers
<?php $header_blob = ' Set-Cookie: PART_NUMBER=ROCKET_LAUNCHER_0001; path=/ Set-Cookie: PART_NUMBER=RIDING_ROCKET_0023; path=/ammo ';
Extract cookie headers
$cookies = array(); if (preg_match_all('/Set-Cookie:\s*(?P<cookies>.+?);/i', $header_blob, $matches)) { foreach ($matches['cookies'] as $cookie) { $cookies[] = $cookie; } $cookies = array_unique($cookies); } var_dump($cookies);
Resend Cookies
$cookie_blob = implode('; ', $cookies); var_dump($cookie_blob);
source share