1

I want to keep the session of user logged in to my website to persist even after the user turns off the browser or the user shuts down its system. The user session will exist until he logs out or clears the browser cookie.

Currently I have user ini_set("session.cookie_lifetime",2678400); which will keep the session to persist for a month.

The behavior is as follow:

  1. User visits the site. Logs in. The session is set and exist.
  2. User turns the browser off.
  3. User again visits to the site. I check the cookie name of session id, which was same as the cookie name of session id set earlier.
  4. The user session is same. But the log in doesn't show. Also If I browse, the user session is shown after browsing 2-3 pages. Even though i didn't logged in again.

Can anyone tell why is it that the login session is not shown as the user opens the browser and comes to site and shown after several refresh of same page or browsing other pages.

any help ?

  • You should not use sessions to “permanently” store data in the first place. – CBroe Sep 22 '14 at 12:36
  • a session-cookie is a cookie...for 1 session. So if you don't want a cookie for 1 session, don't use a session cookie, but just a cookie. – DoXicK Sep 22 '14 at 12:37
  • All my data is stored in session , I just save that session id in cookie, just to check if the session before and now is same or different. What is the other alternative to keep the user login session active after browser is closed and reopened, until the user logout ? –  Sep 22 '14 at 12:43
  • [questions/3128985/php-loginsystem-remember-me](http://stackoverflow.com/questions/3128985/php-loginsystem-remember-me) explains how to implement 'auto login' system. – Ryan Vincent Sep 22 '14 at 14:07
  • Either store the data in the Cookie, or if its sensitive, or too large, store it in a database and load it back into the session based on an id stored in the Cookie. – Garreth McDaid Sep 22 '14 at 22:10

0 Answers0