Session class for CakePHP.
CakePHP abstracts the handling of sessions. There are several convenient methods to access session information. This class is the implementation of those methods. They are mostly used by the Session Component.
string
boolean
string
integer
array
string
string
integer
string
integer
Number of requests that can occur during a session time without the session being renewed. This feature is only used when config value Session.autoRegenerate
is set to true.
integer
integer
integer
boolean
Tests that the user agent is valid and that the session hasn't 'timed out'. Since timeouts are implemented in CakeSession it checks the current static::$time against the time the session is set to expire. The User agent is only checked if Session.checkAgent == true.
Returns the session id. Calling this method will not auto start the session. You might have to manually assert a started session.
_configureSession( )
Helper method to initialize a session, based on CakePHP core settings.
Sessions can be configured with a few shortcut names as well as have any number of ini settings declared.
CakeSessionException
_defaultConfig( string $name )
Get one of the prebaked default session configurations.
$name
_error( integer $errorNumber )
Return error description for given error number.
$errorNumber
_getHandler( string $handler )
Find the handler class and make sure it implements the correct interface.
$handler
CakeSessionException
_hasSession( )
Returns whether a session exists
_overwrite( array $old , array $new )
Used to write new data to _SESSION, since PHP doesn't like us setting the _SESSION var itself.
$old
$new
_returnSessionVars( )
Returns all session variables.
_setError( integer $errorNumber , string $errorMessage )
Helper method to set an internal error message.
$errorNumber
$errorMessage
_setHost( string $host )
Set the host name
$host
_setPath( string|null $base null )
Setup the Path variable
$base
optional null _startSession( )
Helper method to start a session
_validAgentAndTime( )
Tests that the user agent is valid and that the session hasn't 'timed out'. Since timeouts are implemented in CakeSession it checks the current static::$time against the time the session is set to expire. The User agent is only checked if Session.checkAgent == true.
check( string $name )
Returns true if given variable is set in session.
$name
clear( boolean $renew true )
Clears the session.
Optionally also clears the session id and renews the session.
$renew
optional true consume( string $name )
Reads and deletes a variable from session.
$name
The value of the session variable, null if session not available, session not started, or provided name not found in the session.
delete( string $name )
Removes a variable from session.
$name
error( )
Returns last occurred error as a string, if any.
id( string|null $id null )
Returns the session id. Calling this method will not auto start the session. You might have to manually assert a started session.
Passing an id into it, you can also replace the session id if the session has not already been started. Note that depending on the session handler, not all characters are allowed within the session id. For example, the file session handler only allows characters in the range a-z A-Z 0-9 , (comma) and - (minus).
$id
optional null init( string|null $base null )
Pseudo constructor.
$base
optional null read( string|null $name null )
Returns given session variable, or all of them, if no parameters given.
$name
optional null The value of the session variable, null if session not available, session not started, or provided name not found in the session, false on failure.
started( )
Determine if Session has been started.
userAgent( string|null $userAgent null )
Get / Set the user agent
$userAgent
optional null write( string|array $name , string $value null )
Writes value to given session variable name.
$name
$value
optional null protected static boolean
Whether or not the init function in this class was already called
false
public static integer
Number of requests that can occur during a session time without the session being renewed. This feature is only used when config value Session.autoRegenerate
is set to true.
10
© 2005–2016 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
http://api.cakephp.org/2.8/class-CakeSession.html