previousUsing a database container (Previous) (Next) HTTP_Uploadnext

View this page in Last updated: Sun, 18 Oct 2009
English | Brazilian Portuguese | Chinese | Dutch | French | German | Hungarian | Japanese | Polish | Russian | Spanish | Turkish

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".

Explanation

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().

Example

Use of session_set_cookie_params

<?php
require_once 'HTTP/Session2.php';

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

HTTP_Session2::useCookies(true);

HTTP_Session2::start('s');
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()) {
    
HTTP_Session2::destroy();
}

if (
HTTP_Session2::isIdle()) {
    
HTTP_Session2::destroy();
}

HTTP_Session2::updateIdle();
?>
previousUsing a database container (Previous) (Next) HTTP_Uploadnext

Download Documentation Last updated: Sun, 18 Oct 2009
Do you think that something on this page is wrong? Please file a bug report or add a note.
User Notes:
There are no user contributed notes for this page.