0

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

Pankaj Jarial
  • 71
  • 2
  • 8

4 Answers4

2

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.

Let me see
  • 5,063
  • 9
  • 34
  • 47
1

You have to use Cookies.

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

Maarkoize
  • 2,601
  • 2
  • 16
  • 34
0

Use cookies, with a predefined expire time, I like 1 year

emuigai
  • 99
  • 1
  • 11
0

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.

Kiel Labuca
  • 1,223
  • 9
  • 13