Making a session persistent

Making a session persistent – This example illustrates how to make a session persist over multiple browser sessions using a so called "session cookie".


When you create a session it needs to be referenced using a sessionID. This sessionID is generally saved either into a cookie or passed along in the URI.

To remember the sessionID across browser sessions, the cookie method is favoured.

To extend the lifetime of this cookie (the standard is that it's only valid until the browser is closed) we use PHP's session_set_cookie_params().


Use of session_set_cookie_params

require_once 'HTTP/Session2.php';

 * set cookie params
session_set_cookie_params(60*60*24// expire in 24 hours
'/',                            // path
'',                 // domain
false,                          // "secure only"
true);                          // only over http


HTTP_Session2::setExpire(60*60*24); // set expire in 24 hours
HTTP_Session2::setIdle(60*60);      // set idle to 1 hour

if (HTTP_Session2::isExpired()) {

if (
HTTP_Session2::isIdle()) {

Using a database container (Previous) HTTP_Upload (Next)
Last updated: Tue, 02 Jun 2009 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

User Notes:

There are no user contributed notes for this page.