How to print session time remaining in php?

后端 未结 1 374
[愿得一人]
[愿得一人] 2021-01-16 11:33

I have a program in PHP and I want to print to the screen how much time the user has until their session expires. I want it to update when they reload the page.

For

相关标签:
1条回答
  • 2021-01-16 12:17

    You can set a cookie with the UNIX time and compare with that.

    setcookie("start", time(), time ()+3600); // saves a cookie with current UNIX time for one hour
    

    Read about setcookie here http://php.net/manual/en/function.setcookie.php
    If you never used it before, be sure to read the begining carefully.

    And compare time like:

    If (isset($_COOKIE["start"]) and $_COOKIE["start"]+3600<time()){
        echo (time()-$_COOKIE["start"])/60 . " minutes left";
    }Else{
        Echo "times up";
    }
    
    0 讨论(0)
提交回复
热议问题