Class THttpSession
THttpSession class
THttpSession provides session-level data management and the related
configurations. To start the session, call THttpSession::open()
; to complete and send
out session data, call THttpSession::close()
; to destroy the session, call THttpSession::destroy()
. If AutoStart is true, then the session will be started once the
session module is loaded and initialized.
To access data stored in session, use THttpSession like an associative array. For example,
$session=new THttpSession; $session->open(); $value1=$session['name1']; // get session variable 'name1' $value2=$session['name2']; // get session variable 'name2' foreach($session as $name=>$value) // traverse all session variables $session['name3']=$value3; // set session variable 'name3'
The following configurations are available for session: setAutoStart AutoStart, setCookieMode CookieMode, setSavePath SavePath, setUseCustomStorage UseCustomStorage, setGCProbability GCProbability, setTimeout Timeout. See the corresponding setter and getter documentation for more information. Note, these properties must be set before the session is started.
THttpSession can be inherited with customized session storage method.
Override THttpSession::_open()
, THttpSession::_close()
, THttpSession::_read()
, THttpSession::_write()
, THttpSession::_destroy()
and THttpSession::_gc()
and set setUseCustomStorage UseCustomStorage
to true. Then, the session data will be stored using the above methods.
By default, THttpSession is registered with TApplication
as the
request module. It can be accessed via TApplication::getSession()
.
THttpSession may be configured in application configuration file as follows,
<module id="session" class="THttpSession" SessionName="SSID" SavePath="/tmp" CookieMode="Allow" UseCustomStorage="false" AutoStart="true" GCProbability="1" UseTransparentSessionID="true" TimeOut="3600" />
where getSessionName SessionName, getSavePath SavePath, getCookieMode CookieMode, getUseCustomStorage UseCustomStorage, getAutoStart AutoStart, getGCProbability GCProbability, getUseTransparentSessionID UseTransparentSessionID and getTimeout TimeOut are configurable properties of THttpSession.
- TComponent
-
TApplicationComponent
-
THttpSession implements IteratorAggregate, ArrayAccess, Countable, IModule
Direct known subclasses
TCacheHttpSessionCopyright: Copyright © 2005-2014 PradoSoft
License: http://www.pradosoft.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 3.0
Located at Web/THttpSession.php
public
string
|
|
public
|
|
public
|
#
init(
Initializes the module. This method is required by IModule. If AutoStart is true, the session will be started. |
public
|
|
public
|
|
public
|
|
public
string
|
|
public
boolean
|
|
public
string
|
|
public
|
|
public
string
|
|
public
|
|
public
string
|
|
public
|
|
public
boolean
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
boolean
|
|
public
|
|
public
integer
|
|
public
|
|
public
boolean
|
|
public
|
|
public
integer
|
|
public
|
|
public
boolean
|
#
_open( string $savePath, string $sessionName )
Session open handler. This method should be overridden if setUseCustomStorage UseCustomStorage is set true. |
public
boolean
|
#
_close( )
Session close handler. This method should be overridden if setUseCustomStorage UseCustomStorage is set true. |
public
string
|
#
_read( string $id )
Session read handler. This method should be overridden if setUseCustomStorage UseCustomStorage is set true. |
public
boolean
|
#
_write( string $id, string $data )
Session write handler. This method should be overridden if setUseCustomStorage UseCustomStorage is set true. |
public
boolean
|
#
_destroy( string $id )
Session destroy handler. This method should be overridden if setUseCustomStorage UseCustomStorage is set true. |
public
boolean
|
#
_gc( integer $maxLifetime )
Session GC (garbage collection) handler. This method should be overridden if setUseCustomStorage UseCustomStorage is set true. |
public
|
#
getIterator( )
Returns an iterator for traversing the session variables. This method is required by the interface IteratorAggregate. |
public
integer
|
|
public
integer
|
#
count( )
Returns the number of items in the session. This method is required by Countable interface. |
public
array
|
|
public
mixed
|
#
itemAt( mixed $key )
Returns the session variable value with the session variable name. This
method is exactly the same as |
public
|
#
add( mixed $key, mixed $value )
Adds a session variable. Note, if the specified name already exists, the old value will be removed first. |
public
mixed
|
|
public
|
|
public
boolean
|
|
public
array
|
|
public
boolean
|
|
public
mixed
|
|
public
|
|
public
|
getApplication(),
getRequest(),
getResponse(),
getService(),
getSession(),
getUser(),
publishAsset(),
publishFilePath()
|
GLOBAL_RAISE_EVENT_LISTENER
|