When Session Cookies Expire Using cURL When Session Cookies Expire Using cURL curl curl

When Session Cookies Expire Using cURL


According to mozilla.org:

session cookie [...] is deleted when the client shuts down, because it didn't specify an Expires or Max-Age directive. However, web browsers may use session restoring, which makes most session cookies permanent, as if the browser was never closed.

According to the documentation of curl_setopt function:

By default, libcurl always stores and loads all cookies, independent if they are session cookies or not. Session cookies are cookies without expiry date and they are meant to be alive and existing for this "session" only.

If you save a cookie in a 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);

Then, from the client perspective, the session will be active as long as CURLOPT_COOKIEJAR is set with the right cookie. This is a choice of your script.