Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does a cookie with expiration time 'At end of session' expire?

Tags:

php

cookies

There is a session cookie with expiration time which says 'At end of session'. When exactly does it expire or will it be alive forever?

like image 809
Shakti Singh Avatar asked Nov 09 '10 09:11

Shakti Singh


People also ask

How do cookies expire at end of session?

To set a cookie so it expires at the end of the browsing session, simply OMIT the expiration parameter altogether. Show activity on this post. End of the user session means when the browser is shut down. Not anymore.

Can you set an expiration date and time for a cookie?

You can extend the life of a cookie beyond the current browser session by setting an expiration date and saving the expiry date within the cookie. This can be done by setting the 'expires' attribute to a date and time.

What happens when a browser cookie expires?

If a cookie has expired, the browser does not send that particular cookie to the server with the page request; instead, the expired cookie is deleted.


2 Answers

Cookies that 'expire at end of the session' expire unpredictably from the user's perspective!

On iOS with Safari they expire whenever you switch apps!

On Android with Chrome they don't expire when you close the browser.

On Windows desktop running Chrome they expire when you close the browser. That's not when you close your website's tab; its when you close all tabs. Nor do they expire if there are any other browser windows open. If users run web apps as windows they might not even know they are browser windows. So your cookie's life depends on what the user is doing with some apparently unrelated app.

like image 193
James Avatar answered Sep 17 '22 01:09

James


When you use setcookie, you can either set the expiration time to 0 or simply omit the parameter - the cookie will then expire at the end of session (ie, when you close the browser).

like image 44
mingos Avatar answered Sep 17 '22 01:09

mingos