Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - Session destroy after closing browser

Though this question has multiple duplicates i could not find proper solution for me. Need Some help.

I have used ini_set('session.cookie_lifetime', 0); in my configuration file.

But it is not helping me to destroy session on browser close.

Application current flow:

1) In authentication page if user is valid, generate new session identifier using session_regenerate_id(true);

2) Control goes to welcome.php where i start new session using session_start();

3) in logout page code is

      $_SESSION = array();
      if (ini_get("session.use_cookies")) {
        $params = session_get_cookie_params();
        setcookie(session_name(), '', time() - 42000,
        $params["path"], $params["domain"],
        $params["secure"], $params["httponly"]
      );
     }
    // Finally, destroy the session.
    session_destroy();
like image 384
Shri Avatar asked Jun 25 '14 06:06

Shri


People also ask

Is session destroy when browser is closed?

Browsers deletes the session cookies when the browser is closed, if you close it normally and not only kills the process, so the session is permanently lost on the client side when the browser is closed.

Is session destroyed when browser is closed PHP?

Closing tabs does not end sessions only until the browser is closed will it destroy the session. Assuming you didn't tell the browser to always save sessions on close.

Which of the following is destroyed when the browser is closed?

The cookie SHOULD be destroyed when the browser is closed (if Firefox doesn't remove the cookie than it is a problem with Firefox), and is typically NOT saved.


1 Answers

This might help you,

session_set_cookie_params(0);
session_start();

Your session cookie will be destroyed... so your session will be good until the browser is open. please view http://www.php.net//manual/en/function.session-set-cookie-params.php this may help you.

like image 199
Adil Abbasi Avatar answered Sep 29 '22 05:09

Adil Abbasi