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 HTTP_Session2 provides more advanced features such as database containers, idle and expire timeouts and more.
Setting options and detecting a new session
<?php
HTTP_Session2::useCookies(false);
HTTP_Session2::start('MySessionID');
HTTP_Session2::set('variable', 'The string');
if (HTTP_Session2::isNew()) {
echo 'new session was created with the current request';
$visitors++; // Increase visitors count
}
// continue
?>
Setting timeouts
<?php
HTTP_Session2::start();
HTTP_Session2::setExpire(time() + 60 * 60); // expires in one hour
HTTP_Session2::setIdle(time() + 10 * 60); // idles in ten minutes
// the session expired
if (HTTP_Session2::isExpired()) {
echo 'Your session has expired!';
HTTP_Session2::destroy();
}
// the session is idle
if (HTTP_Session2::isIdle()) {
echo "You've been idle for too long!";
HTTP_Session2::destroy();
}
HTTP_Session2::updateIdle();
?>
For a more comprehensive example of persistent sessions, please check the cookie section.