When session cookies end using cURL

Typically, when using a browser, session cookies expire when the browser window is closed.

But when you use (php) cURL (and set the COOKIE_FILEand options COOKIE_JAR), how long do they last?

+4
source share
1 answer

According to mozilla.org :

The session cookie [...] is deleted when the client shuts down because it did not specify the Expires or Max-Age directive. However, web browsers can use session recovery , which makes most session cookies persistent, as if the browser never closed.

According to function documentationcurl_setopt :

By default, libcurl always stores and loads all cookies, regardless of whether they are session files or not. Cookie session cookies are cookies without an expiration date and they must be alive and existing for this session "only.

If you save the cookie in the specified file with

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://stackoverflow.com');
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/cookie.txt');
$output = curl_exec($ch);
curl_close($ch);

, , , CURLOPT_COOKIEJAR cookie. script.

-1

All Articles