API16

JSessionStorageDatabase/gc

< API16:JSessionStorageDatabase

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description

Garbage collect stale sessions from the SessionHandler backend.



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();
}



Examples

Code Examples


Advertisement