Introduction

Introduction – Introduction to HTTP_Session

Overview

This package provides access to session-state values as well as session-level settings and lifetime management methods. Based on the standart PHP session handling mechanism it provides more advanced features such as database containers, idle and expire timeouts, etc.

A few examples

Setting some options and detection of a new session

<?php
HTTP_Session
::setCookieless(false);
HTTP_Session::start('MySessionID');
HTTP_Session::set('variable''Tet string');
if (
HTTP_Session::isNew()) {
    echo(
'new session was created with the current request');
    
$visitors++; // Increase visitors count
}

// after successful login use: HTTP_Session::regenerateId();
?>

Setting timeouts

<?php
HTTP_Session
::start();
HTTP_Session::setExpire(time() + 60 60); // expires in one hour
HTTP_Session::setIdle(time() + 10 60);   // idles in ten minutes

// expired
if (HTTP_Session::isExpired()) {
    echo(
'Your session is expired!');
    
HTTP_Session::destroy();
}

// idled
if (HTTP_Session::isIdle()) {
    echo(
'You've been idle for too long!');
    HTTP_Session::destroy();
}

HTTP_Session::updateIdle();
?>