Friday, February 15, 2013

php session auto destory after limit of second

<?php
header.php
this header function automatic redirect user does not required clik any page
 header( "refresh:60;url=wherever.php" );
-----------------------------------------------------------
logout.php
session_start();
// set time-out period (in seconds)
$auto_inactive_time = 60;

// check to see if $_SESSION["timeout"] is set
if (isset($_SESSION["timeout"])) {
    // calculate the session's "time to live"
    $sessionTTL = time() - $_SESSION["timeout"];
    if ($sessionTTL > $auto_inactive_time) {
        session_destroy();
        header("Location: /logout.php");
    }
}

echo $_SESSION["timeout"] = time()."<br>";
?>

No comments:

Post a Comment