CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 2.1 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.1
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Packages

  • Cake
    • Cache
      • Engine
    • Configure
    • Console
      • Command
        • Task
    • Controller
      • Component
        • Acl
        • Auth
    • Core
    • Error
    • Event
    • I18n
    • Log
      • Engine
    • Model
      • Behavior
      • Datasource
        • Database
        • Session
    • Network
      • Email
      • Http
    • Routing
      • Route
    • TestSuite
      • Coverage
      • Fixture
      • Reporter
    • Utility
    • View
      • Helper

Classes

  • CakeSession
  • DataSource
  • DboSource

Class CakeSession

Session class for Cake.

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

Package: Cake\Model\Datasource
Copyright: Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
License: License (http://www.opensource.org/licenses/mit-license.php)
Location: Cake/Model/Datasource/CakeSession.php

Properties summary

  • $_userAgent protected static
    string
    User agent string
  • $cookieLifeTime public static
    integer
    Cookie lifetime
  • $error public static
    array
    Error messages for this session
  • $host public static
    string
    Hostname
  • $id public static
    string
    Current Session id
  • $lastError public static
    integer
    Error number of last occurred error
  • $path public static
    string
    Path to where the session is active.
  • $requestCountdown 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.

  • $sessionTime public static
    integer
    Time when this session becomes invalid.
  • $time public static
    integer
    Start time for this session.
  • $timeout public static
    integer
    Session timeout multiplier factor
  • $valid public static
    boolean
    True if the Session is still valid

Method Summary

  • _checkValid() protected static
    Helper method to create a new session.
  • _configureSession() protected static
    Helper method to initialize a session, based on Cake core settings.
  • _defaultConfig() protected static
    Get one of the prebaked default session configurations.
  • _error() protected static
    Return error description for given error number.
  • _getHandler() protected static
    Find the handler class and make sure it implements the correct interface.
  • _overwrite() protected static
    Used to write new data to _SESSION, since PHP doesn't like us setting the _SESSION var itself
  • _returnSessionVars() protected static
    Returns all session variables.
  • _setError() protected static
    Helper method to set an internal error message.
  • _setHost() protected static
    Set the host name
  • _setPath() protected static
    Setup the Path variable
  • _startSession() protected static
    Helper method to start a session
  • _validAgentAndTime() protected static

    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 self::$time against the time the session is set to expire. The User agent is only checked if Session.checkAgent == true.

  • check() public static
    Returns true if given variable is set in session.
  • clear() public static
    Clears the session, the session id, and renew's the session.
  • delete() public static
    Removes a variable from session.
  • destroy() public static
    Helper method to destroy invalid sessions.
  • error() public static
    Returns last occurred error as a string, if any.
  • id() public static
    Returns the Session id
  • init() public static
    Constructor.
  • read() public static
    Returns given session variable, or all of them, if no parameters given.
  • renew() public static
    Restarts this session.
  • start() public static
    Starts the Session.
  • started() public static
    Determine if Session has been started.
  • userAgent() public static
    Get / Set the userAgent
  • valid() public static
    Returns true if session is valid.
  • write() public static
    Writes value to given session variable name.

Method Detail

_checkValid() protected static ¶

_checkValid( )

Helper method to create a new session.

_configureSession() protected static ¶

_configureSession( )

Helper method to initialize a session, based on Cake core settings.

Sessions can be configured with a few shortcut names as well as have any number of ini settings declared.

Throws
CakeSessionException
Throws exceptions when ini_set() fails.

_defaultConfig() protected static ¶

_defaultConfig( string $name )

Get one of the prebaked default session configurations.

Parameters
string $name
Returns
boolean|array

_error() protected static ¶

_error( integer $errorNumber )

Return error description for given error number.

Parameters
integer $errorNumber
Error to set
Returns
string
Error as string

_getHandler() protected static ¶

_getHandler( string $handler )

Find the handler class and make sure it implements the correct interface.

Parameters
string $handler
Throws
CakeSessionException

_overwrite() protected static ¶

_overwrite( array $old , array $new )

Used to write new data to _SESSION, since PHP doesn't like us setting the _SESSION var itself

Parameters
array $old
Set of old variables => values
array $new
New set of variable => value

_returnSessionVars() protected static ¶

_returnSessionVars( )

Returns all session variables.

Returns
mixed
Full $_SESSION array, or false on error.

_setError() protected static ¶

_setError( integer $errorNumber , string $errorMessage )

Helper method to set an internal error message.

Parameters
integer $errorNumber
Number of the error
string $errorMessage
Description of the error

_setHost() protected static ¶

_setHost( string $host )

Set the host name

Parameters
string $host
Hostname

_setPath() protected static ¶

_setPath( string $base = null )

Setup the Path variable

Parameters
string $base optional null
base path

_startSession() protected static ¶

_startSession( )

Helper method to start a session

Returns
boolean
Success

_validAgentAndTime() protected static ¶

_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 self::$time against the time the session is set to expire. The User agent is only checked if Session.checkAgent == true.

Returns
boolean

check() public static ¶

check( string $name = null )

Returns true if given variable is set in session.

Parameters
string $name optional null
Variable name to check for
Returns
boolean
True if variable is there

clear() public static ¶

clear( )

Clears the session, the session id, and renew's the session.

delete() public static ¶

delete( string $name )

Removes a variable from session.

Parameters
string $name
Session variable to remove
Returns
boolean
Success

destroy() public static ¶

destroy( )

Helper method to destroy invalid sessions.

error() public static ¶

error( )

Returns last occurred error as a string, if any.

Returns
mixed
Error description as a string, or false.

id() public static ¶

id( string $id = null )

Returns the Session id

Parameters
string $id optional null
Returns
string
Session id

init() public static ¶

init( string $base = null )

Constructor.

Parameters
string $base optional null
The base path for the Session

read() public static ¶

read( mixed $name = null )

Returns given session variable, or all of them, if no parameters given.

Parameters
mixed $name optional null
The name of the session variable (or a path as sent to Set.extract)
Returns
mixed
The value of the session variable

renew() public static ¶

renew( )

Restarts this session.

start() public static ¶

start( )

Starts the Session.

Returns
boolean
True if session was started

started() public static ¶

started( )

Determine if Session has been started.

Returns
boolean
True if session has been started.

userAgent() public static ¶

userAgent( string $userAgent = null )

Get / Set the userAgent

Parameters
string $userAgent optional null
Set the userAgent

valid() public static ¶

valid( )

Returns true if session is valid.

Returns
boolean
Success

write() public static ¶

write( mixed $name , string $value = null )

Writes value to given session variable name.

Parameters
mixed $name
Name of variable
string $value optional null
Value to write
Returns
boolean
True if the write was successful, false if the write failed

Properties detail

$_userAgent ¶

protected static string

User agent string

''

$cookieLifeTime ¶

public static integer

Cookie lifetime

$error ¶

public static array

Error messages for this session

false

$host ¶

public static string

Hostname

null

$id ¶

public static string

Current Session id

null

$lastError ¶

public static integer

Error number of last occurred error

null

$path ¶

public static string

Path to where the session is active.

'/'

$requestCountdown ¶

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.

See
CakeSession::_checkValid()
10

$sessionTime ¶

public static integer

Time when this session becomes invalid.

false

$time ¶

public static integer

Start time for this session.

false

$timeout ¶

public static integer

Session timeout multiplier factor

null

$valid ¶

public static boolean

True if the Session is still valid

false
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs