1

So I'm trying to keep my users logged in with cookies. When the user closes the browser and reopens it, it relogs them in, which is great.

The problem is that when the user quits a browser or restarts their computer, the cookie is lost.

How can I keep the cookie from being lost? Or am I going about this the wrong way.

P.S. I've made sure that the cookie is randomly generated, salted and hashed.

1 Answers1

4

There are two types of cookies:

Session cookies - these are temporary cookie files, which are erased when you close your browser. When you restart your browser and go back to the site that created the cookie, the website will not recognize you. You will have to log back in (if login is required) or select your preferences/themes again if the site uses these features. A new session cookie will be generated, which will store your browsing information and will be active until you leave the site and close your browser.

Persistent cookies – these files stay in one of your browser's subfolders until you delete them manually or your browser deletes them based on the duration period contained within the persistent cookie's file .

To make a cookie persistent, use for example

setcookie( "cookieName2", $value2, strtotime( '+365 days' ) );

for more information , click here

pola sai ram
  • 832
  • 7
  • 23