1

I am using following PHP function to do login and add session while login. I want my session to be automatically end after 30 minutes. Any suggestions out there ?

public function doLogin($uname,$upass)
{
    try
    {
        $stmt = $this->conn->prepare("SELECT user_id, user_name, user_pass FROM users WHERE user_name=:uname");
        $stmt->execute(array(':uname'=>$uname));
        $userRow=$stmt->fetch(PDO::FETCH_ASSOC);
        if($stmt->rowCount() == 1)
        {
            if(password_verify($upass, $userRow['user_pass']))
            {
                $_SESSION['user_session'] = $userRow['user_id'];
                return true;
            }
            else
            {
                return false;
            }
        }
    }
    catch(PDOException $e)
    {
        echo $e->getMessage();
    }
}
Sark
  • 299
  • 2
  • 21
  • http://stackoverflow.com/questions/520237/how-do-i-expire-a-php-session-after-30-minutes – shudder Jun 16 '16 at 05:55
  • [http://stackoverflow.com/questions/17179249/session-destroy-after-certain-amount-of-time-in-php](http://stackoverflow.com/questions/17179249/session-destroy-after-certain-amount-of-time-in-php) Your Answer is here. – Tejas Mehta Jun 16 '16 at 06:12

1 Answers1

0

for this to be automatic , you can use some funtion in javascript or jquery

or

you can set a time to a cookie like that:

setcookie("ses", "" , time() - 3600, "/");

time() - 3600 is a 1 hour , and when the user chage the page , the session will be closed