Like Us on Facebook

How to expire PHP sessions after set a period of time

This post is about “How to expire PHP sessions after set a period of time”. In this post I’ll show you how to expire a user’s session after 6 minutes of inactivity.
 
<?php
    session_start();
    
    if(isset($_SESSION['login_user_mail_address']))
    {
      
 // set time-out period (in seconds)
        $inactive = 600;
         
        
// 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 > $inactive) {
                    session_destroy();
                    
                  
 ?>
                        // Page redirection
                        <script>window.location = 'logout.php';</script>
                    <?php
                  
                }
            }
             
            $_SESSION["
timeout"] = time();
    
    }

?>

 

Posted By UandBlog

UandBlog is a Global Leading source of Finance, Health, Lifestyle, Technology, Gaming and Programing and other information, it is a fastest growing blog for all , for latest post or information like us on facebook , follow on Twitter, Google+ and Pinterest.

Comments ( 0 )

    Leave a comment..

    Click to login.