O
O
Omich2014-11-26 01:33:05
PHP
Omich, 2014-11-26 01:33:05

How long will the cookie live if the session has not ended?

Good afternoon.
The following question arose: if I take and set the cookie lifetime to +15 minutes from the current time when entering the site, but the user stays there longer, how will the cookie behave: it will die during the session, or at the end of the session, or at the next entrance ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Ezhgurov, 2014-11-26
@omichkun

What is important is not the time the user spent on the site, but the time between two calls to the server (this can be the user's transition to another page, loading content with AJAX, etc.).
The session sets a cookie containing the session id at the time the page was opened. After the page is committed to the browser, the session state is archived.
If less than 15 minutes have passed between calls to the server, then the server will take the session id from the cookie and use this id to restore the session state from the archive. In this case, the cookie lifetime will move +15 minutes from the current one.
If more than 15 minutes have passed, then the cookie will be deleted and the next time the server accesses it, it will not be able to read the session id - therefore it will automatically create a new session with a new id and this id will be written to the newly created cookie.

F
FanatPHP, 2014-11-26
@FanatPHP

The question is not very clear. What cookie are you talking about? How is it related to the session?
What session are you talking about? About the session with the site or about the PHP session?
If we are talking about the cookie in which the session identifier is transmitted, then you don’t need to touch it at all, leaving all the default parameters, including the lifetime.
In this case, the cookie lifetime will be set to 0, and the cookie will live exactly as long as the session lasts - no more and no less.
If you still get playful hands into the settings and set the cookie lifetime to 15 minutes, then the PHP session will die along with the cookie, of course.
If you have any questions, then first be sure to read what a session is .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question