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
  • 5,042
  • 16
  • 55
  • 64

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
  • 41,517
  • 32
  • 98
  • 131
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,202
  • 17
  • 48
0

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

Harold
  • 1,068
  • 4
  • 14
  • 35
0

You should use cookies for this: cookies

Alex Pliutau
  • 21,392
  • 27
  • 113
  • 143