Is possible to keep session even after the browser is closed?

Use session_set_cookie_parameters() to give the session cookie a non-zero lifetime before starting the session, or set session.cookie_lifetime to non-zero.


It's oxymoron.
Session stands for "until browser is closed".
Session is something that expires.
If you don't want it to be expired, you're probably don't want a session at all.

You are probably messing session with cookie or database.


Session in php (and in most web technologies) work like this :

You store a session id in a cookie on the client computer.

When the client come to your site he send you the session id.

The server find the session datas in a file with the session id and load it.

So closing the browser has not effect on the session, but if the browser empty the cookie when you close it (I don't think any browser do such a thing).

If you wana be sure the user is always logged in, you can store it's user/password in his cookies but it's not really safe.


The easiest and best i have found is that instead of just session_start we should input this on each page there is a session

$expire = 365*24*3600; // We choose a one year duration

ini_set('session.gc_maxlifetime', $expire);

session_start(); //We start the session 

setcookie(session_name(),session_id(),time()+$expire); 
//Set a session cookies to the one year duration