Show DevBest Session Timeout

Was this helpful ?

  • No, thank you.

    Votes: 0 0.0%

  • Total voters
    3
Status
Not open for further replies.

Khalil

IDK
Dec 6, 2011
1,642
786
Hello everyone, so it's been a very longtime since i have posted anything on this section, so decided to do small thread and share a small script i'm currently using for .

This script works as follows, you put the code into any page you like (a page where the session is started) and then set a certain amount of seconds, once that amount of seconds is reached the sessions is automatically destroyed.

The code is:
PHP:
$inactive = SET THIS INTO SECONDS;
 
if (isset($_SESSION["timeout"])) {
    $sessionTTL = time() - $_SESSION["timeout"];
    if ($sessionTTL > $inactive) {
        session_destroy();
        header("Location: /logout.php"); <-- you can change this page to any page you want.
    }
}
 
$_SESSION["timeout"] = time();

As, you saw this was a very simple code, nothing hard, hope it will come handy for you & thank you for your time.

- Khalil
 

Xyro

Elite Member
Oct 28, 2011
340
100
Thanks for sharing, to be honest, I didn't know how to do this until now facepalm.jpg, so thanks =]
 

Khalil

IDK
Dec 6, 2011
1,642
786
Thanks for sharing, to be honest, I didn't know how to do this until now facepalm.jpg, so thanks =]

No problem, many don't know how, hence why you find good people sharing scripts all over here.
Hope it comes handy sometime.
 

Integers

Soon to be Developer!
Sep 22, 2012
119
7
Aha that's alot better than my log out script (obviously), Thanks for sharing! :)
 
Status
Not open for further replies.

Users who are viewing this thread

Top