2

I don't know how to write php code for Stay logged in or remember me while user check the option while login. I want to stay user logged in at least 60min until user close the browser. What is the code for this in PHP.

KillerFish
  • 4,914
  • 15
  • 54
  • 63

4 Answers4

2

If you are using session. These threads will help you:

You can use session_set_cookie_params to set specific time of session life.

Community
  • 1
  • 1
Naveed
  • 40,370
  • 32
  • 94
  • 130
1

if you are using session, this would probably help

function lifetime(){
    $inactive = 3600; //60 minutes, i suppose in seconds
    if(isset($_SESSION['start']) ) {
        $session_life = time() - $_SESSION['start'];
        if($session_life > $inactive){
            //your log out code
        }
    }
    $_SESSION['start'] = time();
}
littlechad
  • 1,172
  • 14
  • 46
0

http://www.tizag.com/phpT/phpsessions.php This should be helpful

Harold
  • 1,054
  • 3
  • 13
  • 30
0

You should use cookies for this: cookies

Alex Pliutau
  • 20,640
  • 26
  • 107
  • 142