Class CHttpSession
CHttpSession provides session-level data management and the related configurations.
To start the session, call CHttpSession::open()
; To complete and send out session
data, call CHttpSession::close()
; To destroy the session, call CHttpSession::destroy()
.
If CHttpSession::$autoStart
is set true, the session will be started automatically
when the application component is initialized by the application.
CHttpSession can be used like an array to set and get session data. For example,
$session=new CHttpSession; $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:
- setSessionID sessionID;
- setSessionName sessionName;
CHttpSession::$autoStart
;- setSavePath savePath;
- setCookieParams cookieParams;
- setGCProbability gcProbability;
- setCookieMode cookieMode;
- setUseTransparentSessionID useTransparentSessionID;
- setTimeout timeout.
CHttpSession can be extended to support customized session storage. Override
CHttpSession::openSession()
, CHttpSession::closeSession()
, CHttpSession::readSession()
, CHttpSession::writeSession()
, CHttpSession::destroySession()
and CHttpSession::gcSession()
and set useCustomStorage to true. Then, the session data will be stored and retrieved
using the above methods.
CHttpSession is a Web application component that can be accessed via CWebApplication::getSession()
.
- CComponent
- CApplicationComponent implements IApplicationComponent
- CHttpSession implements IteratorAggregate, ArrayAccess, Countable
Copyright: 2008-2013 Yii Software LLC
License: http://www.yiiframework.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 1.0
Located at x2engine/framework/web/CHttpSession.php
public
|
|
public
boolean
|
#
getUseCustomStorage( )
Returns a value indicating whether to use custom session storage. This method
should be overriden to return true if custom session storage handler should be
used. If returning true, make sure the methods |
public
|
|
public
|
|
public
|
|
public
boolean
|
|
public
string
|
|
public
|
|
public
|
#
regenerateID( boolean $deleteOldSession = false )
Updates the current session id with a newly generated one . Please refer to http://php.net/session_regenerate_id for more details. |
public
string
|
|
public
|
|
public
string
|
|
public
|
|
public
array
|
|
public
|
#
setCookieParams( array $value )
Sets the session cookie parameters. The effect of this method only lasts for the duration of the script. Call this method before the session starts. |
public
string
|
|
public
|
|
public
float
|
|
public
|
|
public
boolean
|
|
public
|
|
public
integer
|
|
public
|
|
public
boolean
|
#
openSession( string $savePath, string $sessionName )
Session open handler. This method should be overridden if useCustomStorage is set true. Do not call this method directly. |
public
boolean
|
#
closeSession( )
Session close handler. This method should be overridden if useCustomStorage is set true. Do not call this method directly. |
public
string
|
#
readSession( string $id )
Session read handler. This method should be overridden if useCustomStorage is set true. Do not call this method directly. |
public
boolean
|
#
writeSession( string $id, string $data )
Session write handler. This method should be overridden if useCustomStorage is set true. Do not call this method directly. |
public
boolean
|
#
destroySession( string $id )
Session destroy handler. This method should be overridden if useCustomStorage is set true. Do not call this method directly. |
public
boolean
|
|
public
|
#
getIterator( )
Returns an iterator for traversing the session variables. This method is required by the interface IteratorAggregate. |
public
integer
|
|
public
integer
|
|
public
array
|
|
public
mixed
|
#
get( mixed $key, mixed $defaultValue = null )
Returns the session variable value with the session variable name. This
method is very similar to |
public
mixed
|
#
itemAt( mixed $key )
Returns the session variable value with the session variable name. This
method is exactly the same as |
public
|
|
public
mixed
|
|
public
|
|
public
boolean
|
|
public
array
|
|
public
boolean
|
|
public
mixed
|
|
public
|
|
public
|
getIsInitialized()
|
public
boolean
|
$autoStart | true |
#
whether the session should be automatically started when the session application component is initialized, defaults to true. |
$behaviors
|
public
boolean
|
$useCustomStorage |
#
Whether to use custom storage. |
public
boolean
|
$isStarted |
#
Whether the session has started. |
public
string
|
$sessionID |
#
The current session ID. |
public
string
|
$sessionName |
#
The current session name. |
public
string
|
$savePath |
#
The current session save path, defaults to http://php.net/session.save_path. |
public
array
|
$cookieParams |
#
The session cookie parameters. |
public
string
|
$cookieMode |
#
How to use cookie to store session ID. Defaults to 'Allow'. |
public
float
|
$gCProbability |
#
The probability (percentage) that the gc (garbage collection) process is started on every session initialization, defaults to 1 meaning 1% chance. |
public
boolean
|
$useTransparentSessionID |
#
Whether transparent sid support is enabled or not, defaults to false. |
public
integer
|
$timeout |
#
The number of seconds after which data will be seen as 'garbage' and cleaned up, defaults to 1440 seconds. |
public
|
$iterator |
#
An iterator for traversing the session variables. |
public
integer
|
$count |
#
The number of session variables. |
public
array
|
$keys |
#
The list of session variable names. |
$isInitialized
|