Class \Prado\Web\THttpSession
THttpSession provides session-level data management and the related configurations. To start the session, call open; to complete and send out session data, call close; to destroy the session, call 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: \Prado\Web\setAutoStart, \Prado\Web\setCookieMode, \Prado\Web\setSavePath, \Prado\Web\setUseCustomStorage, \Prado\Web\setGCProbability, \Prado\Web\setTimeout. 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 _open, _close, _read, _write, _destroy and _gc and set \Prado\Web\setUseCustomStorage 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 \Prado\Web\getSessionName, \Prado\Web\getSavePath, \Prado\Web\getCookieMode, \Prado\Web\getUseCustomStorage, \Prado\Web\getAutoStart, \Prado\Web\getGCProbability, \Prado\Web\getUseTransparentSessionID and \Prado\Web\getTimeout are configurable properties of THttpSession.
To avoid the possibility of identity theft through some variants of XSS attacks, THttpSessionshould always be configured to enforce HttpOnly setting on session cookie. The HttpOnly setting is disabled by default. To enable it, configure the THttpSession module as follows,
<module id="session" class="THttpSession" Cookie.HttpOnly="true" >
Class hierarchy
- \Prado\Web\THttpSession implements IteratorAggregate, ArrayAccess, Countable, IModule
- \Prado\TApplicationComponent
- \Prado\TComponent
Since: 3.0
public
|
_close() : bool
Session close handler.
This method should be overridden if \Prado\Web\setUseCustomStorage is set true. |
public
|
_destroy(string $id) : bool
Session destroy handler.
This method should be overridden if \Prado\Web\setUseCustomStorage is set true. |
public
|
_gc(int $maxLifetime) : bool
Session GC (garbage collection) handler.
This method should be overridden if \Prado\Web\setUseCustomStorage is set true. |
public
|
_open(string $savePath, string $sessionName) : bool
Session open handler.
This method should be overridden if \Prado\Web\setUseCustomStorage is set true. |
public
|
_read(string $id) : string
Session read handler.
This method should be overridden if \Prado\Web\setUseCustomStorage is set true. |
public
|
_write(string $id, string $data) : bool
Session write handler.
This method should be overridden if \Prado\Web\setUseCustomStorage is set true. |
public
|
add(mixed $key, mixed $value) : mixed
Adds a session variable.
Note, if the specified name already exists, the old value will be removed first. |
public
|
|
public
|
|
public
|
|
public
|
count() : int
Returns the number of items in the session.
This method is required by \Countable interface. |
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
getIterator() : TSessionIterator
Returns an iterator for traversing the session variables.
This method is required by the interface \IteratorAggregate. |
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
init(TXmlElement $config) : mixed
Initializes the module.
This method is required by IModule. If AutoStart is true, the session will be started. |
public
|
itemAt(mixed $key) : mixed
Returns the session variable value with the session variable name.
This method is exactly the same as offsetGet. |
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
regenerate([bool $deleteOld = false ]) : string
Update the current session id with a newly generated one
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
setUseTransparentSessionID(bool $value) : mixed
Ensure that {@see setCookieMode CookieMode} is not set to "None" before enabling
the use of transparent session ids. Refer to the main documentation of the class
THttpSession class for a configuration example.
|
public
|
\Prado\TApplicationComponent::FX_CACHE_FILE, \Prado\TComponent::GLOBAL_RAISE_EVENT_LISTENER |