开发者

What is the code for Stay logged in or Remember me while user login in PHP

I don't know how to write php code for Stay l开发者_开发问答ogged 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.


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

  • Stay logged in & remember me - PHP sessions and cookies

  • how to logout session if user idle in php

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


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();
}


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


You should use cookies for this: cookies

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜