简体   繁体   中英

Session destroy on browser close

I have heard many times that a session get destroy as our browser close.

Then how I keep logged in after closing and reopening my browser.

Please help

You keep login because your sessions are not destroyed even when the browser is closed. Sessions destroying on the closing of the browser is default behaviour but but this does not mean its the only behaviour . You can extend the expiry time of session.

This behaviour can be changed in the php.ini file by altering the line:

Keeping a session alive indefinitely

 session.cookie_lifetime = 0

So just check when you have set the expiry time for the sessions. Although using cookies will be a good option

Note:- Remember to restart your web server after making this change.

You have to use Cookies.

You can use the setcookie() function and read the value with the $_COOKIE['cookiename'] variable.

使用cookies,预定的到期时间,我喜欢1年

You can use cookies. Cookies are data that is stored directly on the HDD so that even if the browser was closed, cookies still can be read if it haven't expired yet.

Here is an example of setting up a cookie.

Paste this code BEFORE the tag.

<?php setcookie("$name", "$value", $time); ?>

Where $name is the cookie name, $value is the cookie value and $time is the time when your cookie will be expired. For example $time = time()+86400; will set your cookie to expire after 1 day. The 86400 value is the number of seconds in a day, 60seconds times 60minutes times 24hours, so 60x60x24 = 86400.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM