PHP5 Session Class

This is a Session class for you guessed it, managing sessions. Back in the day, when there weren't many open source frameworks on the market, developers had to code things from scratch to achieve certain functionality. This class's inception, is the from one of those instances. With this class you can easily time-out your authenticated users after a specified interval.

How to use it

Note: You always want the session to be the first thing that runs before any output is sent to the browser.

The first thing you'll need to do is register a session. You'll do this when your authenticating a user to access specific areas of your site.

<?php
require_once('Class.Session.php');

// Start a new session and define in how many minutes it will expire.
$Session = new Session(60);	

// Register the session with the authenticated user's id.
$Session->registerSession($user_id);
?>

With each page load, you''ll want to check how the session is doing. If it's expired, you'll kick them out and redirect them back to a login page. If not, the session is renewed.

<?php
require_once('Class.Session.php');

// Start a new session and define in how many minutes it will expire.
$Session = new Session(60);

// Check if the session is registered
if($Session->isSessionRegistered()) {
    // Check to see if the session has expired.
    if($Session->isSessionExpired()) {
        $Session->destroySession();
        header('Location: http://www.yoursite.com/login');
        exit;
    }	
    else {
        // Renew the session
        $Session->renewSession();
    }
}	
?>
PHP5 Session Class

Project Technology:
PHP