Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Static Protected Attributes | Static Private Member Functions | List of all members
eZSession Class Reference

## Public Member Functions
| __construct ( $id="", $fetch=true)
| store ()
| get ( $id="")
| fill ( $session_array)
| fetch ( $refresh=true)
| refresh ()
| delete ()
| id ()
| hash ()
| lastAccessed ()
| created ()
| setHash ( $value)
| variable ( $name, $group=false)
| getByVariable ( $name)
| idle ()
| cleanup ( $maxIdle=48)
| setVariable ( $name, $value, $group=false)
| setArray ( $name, $array, $append=false)
| arrayValue ( $name)

## Static Public Member Functions
static & | get ( $key=null, $defaultValue=null)
static | set ( $key, $value)
static | issetkey ( $key, $forceStart=true)
static | unsetkey ( $key, $forceStart=true)
static | garbageCollector ()
static | cleanup ()
static | countActive ()
static | setCookieLifetime ( $lifetime)
static | setCookieParams ( $lifetime=false)
static | start ( $cookieTimeout=false)
static | lazyStart ( $startIfUserHasCookie=true)
static | init ( $name, $started, $ns, ezpSessionHandler $handler)
static | stop ()
static | regenerate ( $updateBackendData=true)
static | remove ()
static | setUserID ( $userID)
static | userID ()
static | userHasSessionCookie ()
static | hasStarted ()
static | getHandlerInstance (ezpSessionHandler|null $handler=null)
static | addCallback ( $type, $callback)
static | triggerCallback ( $type, $params)
static & | globalSession ( $id="", $fetch=true)
static | stop ()

## Public Attributes
| $ID
| $Hash
| $Modified
| $Created
| $LastAccessed
| $StoredVariables
| $StoredIdle
| $HasRefreshed
| $IsFetched

## Protected Member Functions
| __construct ()

## Static Protected Member Functions
static | registerFunctions ( $sessionName=false, ezpSessionHandler|null $handler=null)
static | forceStart ()

## Static Protected Attributes
static | $userID = 0
static | $hasStarted = false
static | $hasSessionCookie = null
static | $callbackFunctions = array()
static | $handlerInstance = null
static | $namespace = null

## Static Private Member Functions
static & | sessionArray ()

## Detailed Description

! eZSession eZSession handles sessions and session variables.

// Create a new session, store it to the database and set a cookie.
$session =& eZSession::globalSession( );
$session->store();
// get the session from the client
// The page must reload before the session cookie is accessable.
$session->fetch();
// set a session variable
$session->setVariable( "CartID", "422" );
// fetch the CartID session variable
$cartID = $session->variable( "CartID" );
// check if the variable exists and print out the contents
if ( $cartID )
{
print( "You have a shopping cart<br>" );
print( "And the ID is: " . $cartID );
}
$session
$session
Definition: admin/articlelist.php:44
eZSession\globalSession
static & globalSession( $id="", $fetch=true)
Definition: kernel/ezsession/classes/ezsession.php:614

Definition at line 64 of file lib/ezsession/classes/ezsession.php.

## Constructor & Destructor Documentation

## ◆ __construct() [1/2]

eZSession::__construct | ( |  | ) |
| protected

Constructor (not used, this is an all static class)

Definition at line 112 of file lib/ezsession/classes/ezsession.php.

## ◆ __construct() [2/2]

eZSession::__construct | ( |  | $id = `""`,
|  |  | $fetch = `true`
| ) |  |

Creates a new eZSession object.

Definition at line 68 of file kernel/ezsession/classes/ezsession.php.

References $id, and $ID.

## Member Function Documentation

## ◆ addCallback()

static eZSession::addCallback | ( |  | $type,
|  |  | $callback
| ) |  |
| static

Adds a callback function, to be triggered by eZSession::triggerCallback() when a certain session event occurs. Use: eZSession::addCallback('gc_pre', myCustomGarabageFunction );

Since
  4.1

Deprecated:
  since 4.5, use ezpEvent::getInstance()->attach() with new events

Parameters

  string | $type | cleanup, gc, destroy, insert and update, pre and post types.
  handler | $callback | a function to call.

Definition at line 622 of file lib/ezsession/classes/ezsession.php.

References $type.

Referenced by ezpbKernelAdmin\requestInit(), ezpbKernelWeb\requestInit(), and ezpKernelWeb\requestInit().

## ◆ arrayValue()

eZSession::arrayValue | ( |  | $name | ) |

Definition at line 586 of file kernel/ezsession/classes/ezsession.php.

References $name, and variable().

## ◆ cleanup() [1/2]

eZSession::cleanup | ( |  | $maxIdle = `48` | ) |

Cleanup function. Will remove old sessions from the database.

The default value is to remove sessions which are older than 48 hours.

This function should be run in a cron job.

Definition at line 471 of file kernel/ezsession/classes/ezsession.php.

References $db, and eZDB\globalDatabase().

## ◆ cleanup() [2/2]

static eZSession::cleanup | ( |  | ) |
| static

Truncates all session data in the database, this function is not supported by session handlers that don't have a session backend on their own.

Since
  4.1

Returns
  bool

Definition at line 243 of file lib/ezsession/classes/ezsession.php.

References getHandlerInstance().

## ◆ countActive()

static eZSession::countActive | ( |  | ) |
| static

Counts the number of active session and returns it, this function is not supported by session handlers that don't have a session backend on their own.

Since
  4.1

Returns
  string Number of sessions.

Definition at line 255 of file lib/ezsession/classes/ezsession.php.

References getHandlerInstance().

## ◆ created()

eZSession::created | ( |  | ) |

Returns the cretation time of the session.

Definition at line 369 of file kernel/ezsession/classes/ezsession.php.

References $dateTime.

## ◆ delete()

eZSession::delete | ( |  | ) |

Deletes an eZSession object from the database.

Definition at line 324 of file kernel/ezsession/classes/ezsession.php.

References $db, and eZDB\globalDatabase().

## ◆ fetch()

eZSession::fetch | ( |  | $refresh = `true` | ) |

Fetches a session from cookie and database.

Fetches a session and stores the result in the global session object.

Returnes false if unsuccessful.

Definition at line 236 of file kernel/ezsession/classes/ezsession.php.

References $db, $ret, eZDB\globalDatabase(), and refresh().

## ◆ fill()

eZSession::fill | ( |  | $session_array | ) |

Fills in object information from the database array.

Definition at line 219 of file kernel/ezsession/classes/ezsession.php.

References $db, and eZDB\globalDatabase().

Referenced by get().

## ◆ forceStart()

static eZSession::forceStart | ( |  | ) |
| static protected

See eZSession::start()

See also
  ezpSessionHandler::sessionStart()

Since
  4.4

Returns
  true

Definition at line 453 of file lib/ezsession/classes/ezsession.php.

References getHandlerInstance().

Referenced by init(), lazyStart(), and start().

## ◆ garbageCollector()

static eZSession::garbageCollector | ( |  | ) |
| static

Deletes all expired session data in the database, this function is not supported by session handlers that don't have a session backend on their own.

Since
  4.1

Returns
  bool

Definition at line 231 of file lib/ezsession/classes/ezsession.php.

References getHandlerInstance().

## ◆ get() [1/2]

eZSession::get | ( |  | $id = `""` | ) |

Fetches the object information from the database.

Definition at line 169 of file kernel/ezsession/classes/ezsession.php.

References $db, $id, $ret, fill(), eZDB\globalDatabase(), and eZDebug\writeError().

## ◆ get() [2/2]

static& eZSession::get | ( |  | $key = `null`,
|  |  | $defaultValue = `null`
| ) |  |
| static

Get session value (wrapper)

Since
  4.4

Parameters

  string | null | $key | Return the whole session array if null otherwise the value of $key
  null | mixed | $defaultValue | Return this if not null and session has not started

Returns
  mixed|null $defaultValue if key does not exist, otherwise session value depending on $key

Definition at line 142 of file lib/ezsession/classes/ezsession.php.

References $session, sessionArray(), and start().

## ◆ getByVariable()

eZSession::getByVariable | ( |  | $name | ) |

Returns an array of session ID's session variable name==$name.

Definition at line 419 of file kernel/ezsession/classes/ezsession.php.

References $db, $ret, and eZDB\globalDatabase().

## ◆ getHandlerInstance()

static eZSession::getHandlerInstance | ( | ezpSessionHandler|null | $handler = `null` | ) |
| static

Get curren session handler

Since
  4.4

Returns
  ezpSessionHandler

Definition at line 580 of file lib/ezsession/classes/ezsession.php.

References $handlerInstance, $ini, $options, and eZExtension\getHandlerClass().

Referenced by cleanup(), countActive(), forceStart(), garbageCollector(), regenerate(), registerFunctions(), remove(), ezpbKernelAdmin\sessionInit(), ezpbKernelWeb\sessionInit(), ezpKernelTreeMenu\sessionInit(), and ezpKernelWeb\sessionInit().

## ◆ globalSession()

static& eZSession::globalSession | ( |  | $id = `""`,
|  |  | $fetch = `true`
| ) |  |
| static

Returns a reference to the global session object, if it doesn't exists it is initialized. This is safe to call without an object since it does not access member variables.

Do not call this method unless you want to fetch the global session variable.

Definition at line 614 of file kernel/ezsession/classes/ezsession.php.

References $session.

Referenced by eZUser\currentUser(), eZUser\currentUsers(), eZUser\loginUser(), eZUser\logout(), ezpbKernelWeb\run(), and eZShippingType\vatType().

## ◆ hash()

eZSession::hash | ( |  | ) |

Returns the hash to the session.

Definition at line 350 of file kernel/ezsession/classes/ezsession.php.

References $Hash.

## ◆ hasStarted()

static eZSession::hasStarted | ( |  | ) |
| static

Return value to indicate if session has started or not

Since
  4.4

Returns
  bool

Definition at line 569 of file lib/ezsession/classes/ezsession.php.

References $hasStarted.

Referenced by ezpKernelWeb\run().

## ◆ id()

eZSession::id | ( |  | ) |

Returns the id to the session.

Definition at line 342 of file kernel/ezsession/classes/ezsession.php.

References $ID.

## ◆ idle()

eZSession::idle | ( |  | ) |

Returns the idle time of the session in seconds.

Definition at line 440 of file kernel/ezsession/classes/ezsession.php.

References $db, $ret, $StoredIdle, and eZDB\globalDatabase().

## ◆ init()

static eZSession::init | ( |  | $name,
|  |  | $started,
|  |  | $ns,
|  | ezpSessionHandler | $handler
| ) |  |
| static

Initializes the legacy session system with injected settings. This is method is to be used when Symfony2 "drives" the session, it replaces start/lazyStart in such case.

Parameters

  string | $name | Name of the session
  bool | $started | Whether the session is already started or not
  string | $ns | Namespace ie the key under which session data should be put in global array

Definition at line 428 of file lib/ezsession/classes/ezsession.php.

References $name, forceStart(), and registerFunctions().

Referenced by ezpbKernelAdmin\sessionInit(), ezpbKernelWeb\sessionInit(), ezpKernelTreeMenu\sessionInit(), and ezpKernelWeb\sessionInit().

## ◆ issetkey()

static eZSession::issetkey | ( |  | $key,
|  |  | $forceStart = `true`
| ) |  |
| static

Isset session value (wrapper)

Since
  4.4

Parameters

  string | $key |
  bool | $forceStart | Force session start if true

Returns
  bool|null Null if session has not started and $forceStart is false

Definition at line 186 of file lib/ezsession/classes/ezsession.php.

References $session, sessionArray(), and start().

## ◆ lastAccessed()

eZSession::lastAccessed | ( |  | ) |

Returns the last accessed time of the session.

Definition at line 358 of file kernel/ezsession/classes/ezsession.php.

References $dateTime.

## ◆ lazyStart()

static eZSession::lazyStart | ( |  | $startIfUserHasCookie = `true` | ) |
| static

Inits eZSession and starts it if user has cookie and $startIfUserHasCookie is true.

Since
  4.4

Parameters

  bool | $startIfUserHasCookie |

Returns
  bool|null

Definition at line 401 of file lib/ezsession/classes/ezsession.php.

References forceStart(), registerFunctions(), and setCookieParams().

Referenced by ezpbKernelAdmin\sessionInit(), ezpbKernelWeb\sessionInit(), ezpKernelTreeMenu\sessionInit(), and ezpKernelWeb\sessionInit().

## ◆ refresh()

eZSession::refresh | ( |  | ) |

This function refreshes the session timeout.

Definition at line 295 of file kernel/ezsession/classes/ezsession.php.

References $db, $ret, and eZDB\globalDatabase().

Referenced by fetch().

## ◆ regenerate()

static eZSession::regenerate | ( |  | $updateBackendData = `true` | ) |
| static

Will make sure the user gets a new session ID while keepin the session data. This is useful to call on logins, to avoid sessions theft from users. NOTE: make sure you set new user id first using eZSession::setUserID()

Since
  4.1

Parameters

  bool | $updateBackendData | set to false to not update session backend with new session id and user id.

Returns
  bool Depending on if session was regenerated.

Definition at line 485 of file lib/ezsession/classes/ezsession.php.

References getHandlerInstance(), and eZDebug\writeWarning().

## ◆ registerFunctions()

static eZSession::registerFunctions | ( |  | $sessionName = `false`,
|  | ezpSessionHandler|null | $handler = `null`
| ) |  |
| static protected

Register the needed session functions, this is called automatically by eZSession::start(), so only call this if you don't start the session.

Since
  4.1

Returns
  bool Depending on if eZSession is registrated as session handler.

Definition at line 267 of file lib/ezsession/classes/ezsession.php.

References $access, $ini, and getHandlerInstance().

Referenced by init(), and lazyStart().

## ◆ remove()

static eZSession::remove | ( |  | ) |
| static

Removes the current session and resets session variables. Note: implicit stops session as well!

Since
  4.1

Returns
  bool Depending on if session was removed.

Definition at line 512 of file lib/ezsession/classes/ezsession.php.

References $result, and getHandlerInstance().

## ◆ sessionArray()

static& eZSession::sessionArray | ( |  | ) |
| static private

Returns the session array to use taking into account the namespace that might have been injected.

Since
  5.0

Returns
  byRef session array to use

Definition at line 123 of file lib/ezsession/classes/ezsession.php.

References $namespace.

Referenced by get(), issetkey(), set(), and unsetkey().

## ◆ set()

static eZSession::set | ( |  | $key,
|  |  | $value
| ) |  |
| static

Set session value (wrapper)

Since
  4.4

Parameters

  string | $key |

Returns
  bool

Definition at line 166 of file lib/ezsession/classes/ezsession.php.

References $session, sessionArray(), and start().

## ◆ setArray()

eZSession::setArray | ( |  | $name,
|  |  | $array,
|  |  | $append = `false`
| ) |  |

Definition at line 561 of file kernel/ezsession/classes/ezsession.php.

References $i, $name, setVariable(), and variable().

## ◆ setCookieLifetime()

static eZSession::setCookieLifetime | ( |  | $lifetime | ) |
| static

Set the Cookie timeout of session cookie.

Since
  5.0

Parameters

  int | $lifetime | Cookie timeout of the session cookie

Definition at line 322 of file lib/ezsession/classes/ezsession.php.

## ◆ setCookieParams()

static eZSession::setCookieParams | ( |  | $lifetime = `false` | ) |
| static

Set default cookie parameters based on site.ini settings (fallback to php.ini settings) Used by eZSession::registerFunctions(). If you only want to set the cookie lifetime, use eZSession::setCookieLifetime instead. Note: this will only have affect when session is created / re-created

Since
  4.4

Parameters

  int | false | $lifetime | Cookie timeout of session cookie, will read from ini if not set

Definition at line 336 of file lib/ezsession/classes/ezsession.php.

References $ini.

Referenced by lazyStart(), and start().

## ◆ setHash()

eZSession::setHash | ( |  | $value | ) |

Sets the hash to the session.

Definition at line 380 of file kernel/ezsession/classes/ezsession.php.

## ◆ setUserID()

static eZSession::setUserID | ( |  | $userID | ) |
| static

Sets the current userID used by ezpSessionHandlerDB::write() on shutdown.

Since
  4.1

Parameters

  int | $userID | to use in ezpSessionHandlerDB::write()

Definition at line 536 of file lib/ezsession/classes/ezsession.php.

References $userID, and $userID.

Referenced by ezpSessionHandlerDB\read().

## ◆ setVariable()

eZSession::setVariable | ( |  | $name,
|  |  | $value,
|  |  | $group = `false`
| ) |  |

Adds or updates a variable to the session.

Definition at line 493 of file kernel/ezsession/classes/ezsession.php.

References $db, $group, $name, $query, $res, and eZDB\globalDatabase().

Referenced by setArray(), and store().

## ◆ start()

static eZSession::start | ( |  | $cookieTimeout = `false` | ) |
| static

Starts the session and sets the timeout of the session cookie. Multiple calls will be ignored unless you call eZSession::stop() first.

Since
  4.1

Parameters

  int | false | $cookieTimeout | Use this to set custom cookie timeout.

Returns
  bool Depending on if session was started.

Definition at line 384 of file lib/ezsession/classes/ezsession.php.

References forceStart(), and setCookieParams().

Referenced by get(), issetkey(), ezpbKernelAdmin\sessionInit(), ezpbKernelWeb\sessionInit(), ezpKernelTreeMenu\sessionInit(), ezpKernelWeb\sessionInit(), set(), and unsetkey().

## ◆ stop() [1/2]

static eZSession::stop | ( |  | ) |
| static

Writes session data and stops the session, if not already stopped.

Since
  4.1

Returns
  bool Depending on if session was stopped.

Definition at line 635 of file kernel/ezsession/classes/ezsession.php.

## ◆ stop() [2/2]

static eZSession::stop | ( |  | ) |
| static

Writes session data and stops the session, if not already stopped.

Since
  4.1

Returns
  bool Depending on if session was stopped.

Definition at line 464 of file lib/ezsession/classes/ezsession.php.

Referenced by eZFile\download().

## ◆ store()

eZSession::store | ( |  | ) |

Stores a product to the database and sets a cookie to identify the session later.

Definition at line 85 of file kernel/ezsession/classes/ezsession.php.

References $dateTime, $db, $Hash, $res, eZDB\globalDatabase(), and setVariable().

## ◆ triggerCallback()

static eZSession::triggerCallback | ( |  | $type,
|  |  | $params
| ) |  |
| static

Triggers callback functions by type, registrated by eZSession::addCallback() Use: eZSession::triggerCallback('gc_pre', array( $db, $time ) );

Since
  4.1

Deprecated:
  since 4.5, use ezpEvent::getInstance()->notify() with new events

Parameters

  string | $type | cleanup, gc, destroy, insert and update, pre and post types.
  array | $params | list of parameters to pass to the callback function.

Returns
  bool

Definition at line 641 of file lib/ezsession/classes/ezsession.php.

References $type.

Referenced by ezpSessionHandlerDB\cleanup(), ezpSessionHandlerPHP\cleanup(), ezpSessionHandlerDB\destroy(), ezpSessionHandlerDB\gc(), ezpSessionHandlerPHP\gc(), ezpSessionHandlerSymfony\gc(), ezpSessionHandlerDB\regenerate(), ezpSessionHandlerPHP\regenerate(), and ezpSessionHandlerSymfony\regenerate().

## ◆ unsetkey()

static eZSession::unsetkey | ( |  | $key,
|  |  | $forceStart = `true`
| ) |  |
| static

unset session value (wrapper)

Since
  4.4

Parameters

  string | $key |
  bool | $forceStart | Force session start if true

Returns
  bool|null True if value was removed, false if it did not exist and null if session is not started and $forceStart is false

Definition at line 207 of file lib/ezsession/classes/ezsession.php.

References $session, sessionArray(), and start().

## ◆ userHasSessionCookie()

static eZSession::userHasSessionCookie | ( |  | ) |
| static

Returns if user had session cookie at start of request or not.

Since
  4.1

Returns
  bool|null Null if session is not started yet.

Definition at line 558 of file lib/ezsession/classes/ezsession.php.

References $hasSessionCookie.

## ◆ userID()

static eZSession::userID | ( |  | ) |
| static

Gets the current user id.

Since
  4.1

Returns
  int User id stored by eZSession::setUserID()

Definition at line 547 of file lib/ezsession/classes/ezsession.php.

References $userID.

Referenced by ezpSessionHandlerDB\regenerate(), ezpSessionHandlerPHP\regenerate(), ezpSessionHandlerSymfony\regenerate(), and ezpSessionHandlerDB\write().

## ◆ variable()

eZSession::variable | ( |  | $name,
|  |  | $group = `false`
| ) |  |

Returns the value of a session variable.

If the variable does not exist 0 (false) is returned.

Definition at line 390 of file kernel/ezsession/classes/ezsession.php.

References $db, $group, $name, $ret, and eZDB\globalDatabase().

Referenced by arrayValue(), and setArray().

## Member Data Documentation

## ◆ $callbackFunctions

eZSession::$callbackFunctions = array()
| static protected

Definition at line 92 of file lib/ezsession/classes/ezsession.php.

## ◆ $Created

eZSession::$Created

Definition at line 650 of file kernel/ezsession/classes/ezsession.php.

## ◆ $handlerInstance

eZSession::$handlerInstance = null
| static protected

Definition at line 99 of file lib/ezsession/classes/ezsession.php.

Referenced by getHandlerInstance().

## ◆ $Hash

eZSession::$Hash

Definition at line 648 of file kernel/ezsession/classes/ezsession.php.

Referenced by hash(), and store().

## ◆ $HasRefreshed

eZSession::$HasRefreshed

Definition at line 656 of file kernel/ezsession/classes/ezsession.php.

## ◆ $hasSessionCookie

eZSession::$hasSessionCookie = null
| static protected

Definition at line 85 of file lib/ezsession/classes/ezsession.php.

Referenced by userHasSessionCookie().

## ◆ $hasStarted

eZSession::$hasStarted = false
| static protected

Definition at line 78 of file lib/ezsession/classes/ezsession.php.

Referenced by hasStarted().

## ◆ $ID

eZSession::$ID

Definition at line 647 of file kernel/ezsession/classes/ezsession.php.

Referenced by __construct(), and id().

## ◆ $IsFetched

eZSession::$IsFetched

Definition at line 657 of file kernel/ezsession/classes/ezsession.php.

## ◆ $LastAccessed

eZSession::$LastAccessed

Definition at line 651 of file kernel/ezsession/classes/ezsession.php.

## ◆ $Modified

eZSession::$Modified

Definition at line 649 of file kernel/ezsession/classes/ezsession.php.

## ◆ $namespace

eZSession::$namespace = null
| static protected

Definition at line 107 of file lib/ezsession/classes/ezsession.php.

Referenced by sessionArray().

## ◆ $StoredIdle

eZSession::$StoredIdle

Definition at line 654 of file kernel/ezsession/classes/ezsession.php.

Referenced by idle().

## ◆ $StoredVariables

eZSession::$StoredVariables

Definition at line 653 of file kernel/ezsession/classes/ezsession.php.

## ◆ $userID

eZSession::$userID = 0
| static protected

Definition at line 71 of file lib/ezsession/classes/ezsession.php.

Referenced by setUserID(), and userID().

The documentation for this class was generated from the following file:

- lib/ezsession/classes/ezsession.php

Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.