0

I have used sessions all over my website. I have now made a webview android application so it's easier for me and my users to access my website.

The problem with sessions is that when the app/browser closes - the session is destroyed. I wan't to keep that option though - but I would also like to make a "remember me" function.

When I log in. Could I then do something like this:

$UserId = "TheUserId";

if($RememberMe == 1) {
    setcookie('userid', '".$UserId."', time() + (86400 * 30 * 14), "/");
} else {
    setcookie('userid', '".$UserId."', 0, "/");
}

Will the last cookie be deleted after the browser closes and will the first cookie stay around for 14 days?

Thank you very much.

Niels Hermann
  • 611
  • 2
  • 6
  • 13
  • The life of a cookie can be determined by the end-user who may choose to delete them when they close their web browser. Here's an article on this https://www.pcworld.com/article/2846020/how-to-automatically-delete-your-cookies-every-time-you-close-your-browser.html - You can further your research with the following keywords: "do cookies get deleted after browser is closed?". – Funk Forty Niner May 09 '18 at 10:14
  • @FunkFortyNiner - Thank you for your comment. I think I might wrote my question wrong somehow. What I would like to do is that if someone does not click the "remember me"-box, the cookie should get deleted after the browser closes - just like a session would. If the users extend the period of time manually afterwards - that wouldn't matter. – Niels Hermann May 09 '18 at 10:19
  • See https://stackoverflow.com/questions/686155/remove-a-cookie then. – Funk Forty Niner May 09 '18 at 10:22

0 Answers0