Actions

API16

JSessionStorageDatabase/gc

From Joomla! Documentation

< API16:JSessionStorageDatabase
Revision as of 17:40, 22 March 2010 by Doxiki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Garbage collect stale sessions from the SessionHandler backend.

[Edit Descripton]

Description:JSessionStorageDatabase/gc

Syntax

gc($lifetime=1440)
Parameter Name Default Value Description
$lifetime 1440 The maximum age of a session.

Returns

boolean True on success, false otherwise.

Defined in

libraries/joomla/session/storage/database.php

Importing

jimport( 'joomla.session.storage.database' );

Source Body

function gc($lifetime = 1440)
{
        // Get the database connection object and verify its connected.
        $db = &JFactory::getDbo();
        if (!$db->connected()) {
                return false;
        }
 
        // Determine the timestamp threshold with which to purge old sessions.
        $past = time() - $lifetime;
 
        // Remove expired sessions from the database.
        $db->setQuery(
                'DELETE FROM `#__session`' .
                ' WHERE `time` < '.(int) $past
        );
        return (boolean) $db->query();
}

[Edit See Also] SeeAlso:JSessionStorageDatabase/gc

Examples

<CodeExamplesForm />