class DatabaseSessionHandler extends AbstractSessionHandler (View source)

Session save handler that stores session data in the database.

Traits

Provides extensions to this object to integrate it with standard config API methods.

Config options

table_name string

Properties

Methods

protected
int
getLifetime()

Get the session lifetime in seconds.

protected
void
checkSessionID(string $id)

Check the PHP session ID i.e. PHPSESSID is valid against the default PHP session ID format.

public static 
config()

Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).

public
mixed
uninherited(string $name)

Gets the uninherited value for the given config option

public
bool
open(string $path, string $name)

No description

public
bool
close()

No description

public
bool
destroy(string $id)

No description

public
int|false
gc(int $max_lifetime)

No description

public
string|false
read(string $id)

No description

public
bool
write(string $id, string $data)

No description

public
bool
validateId(string $id)

No description

public
bool
updateTimestamp(string $id, string $data)

No description

public
void
requireTable()

Add the database table. This is called by an extension when building the db.

Details

protected int getLifetime()

Get the session lifetime in seconds.

Returns the cookie lifetime if it's non-zero, otherwise returns the garbage collection lifetime.

Return Value

int

protected void checkSessionID(string $id)

Check the PHP session ID i.e. PHPSESSID is valid against the default PHP session ID format.

This is a security measure to prevent people from injecting invalid session IDs in the request.

This only needs to be called on read() We do not need to call this on write(), destroy(), updateTimestamp(), or validateId() as those methods are only called for session IDs that have already been accepted by PHP.

Parameters

string $id

Return Value

void

static Config_ForClass config()

Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).

Return Value

Config_ForClass

mixed uninherited(string $name)

Gets the uninherited value for the given config option

Parameters

string $name

Return Value

mixed

bool open(string $path, string $name)

No description

Parameters

string $path
string $name

Return Value

bool

bool close()

No description

Return Value

bool

bool destroy(string $id)

No description

Parameters

string $id

Return Value

bool

int|false gc(int $max_lifetime)

No description

Parameters

int $max_lifetime

Return Value

int|false

string|false read(string $id)

No description

Parameters

string $id

Return Value

string|false

bool write(string $id, string $data)

No description

Parameters

string $id
string $data

Return Value

bool

bool validateId(string $id)

No description

Parameters

string $id

Return Value

bool

bool updateTimestamp(string $id, string $data)

No description

Parameters

string $id
string $data

Return Value

bool

void requireTable()

Add the database table. This is called by an extension when building the db.

Note that we don't just use a DataObject because:

  1. We don't want things like versioning, fluent, etc to ever be able to affect sessions
  2. We don't want developers to be affecting db operations via hooks (interact with sessions with the Session class)
  3. We don't want sessions to be used in any other ways that DataObjects are often
  4. We only want to build the table if this is the configured save handler

Return Value

void