Yii Framework v1.1.10 绫诲弬鑰

CHttpSession

system.web
缁ф壙 class CHttpSession » CApplicationComponent » CComponent
瀹炵幇 IApplicationComponent, IteratorAggregate, Traversable, ArrayAccess, Countable
瀛愮被 CCacheHttpSession, CDbHttpSession
婧愯嚜 1.0
鐗堟湰 $Id: CHttpSession.php 3511 2011-12-27 00:02:53Z alexander.makarow $
婧愮爜 framework/web/CHttpSession.php
CHttpSession 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 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: See the corresponding setter and getter documentation for more information. Note, these properties must be set before the session is started.

CHttpSession can be extended to support customized session storage. Override openSession, closeSession, readSession, writeSession, destroySession and 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().

鍏叡灞炴

闅愯棌缁ф壙灞炴

灞炴绫诲瀷鎻忚堪瀹氫箟鍦
autoStart boolean whether the session should be automatically started when the session application component is initialized, defaults to true. CHttpSession
behaviors array 杩欎釜搴旂敤缁勪欢闄勫姞鐨勮涓恒 杩欐琛屼负灏嗗湪搴旂敤缁勪欢璋冪敤init鏃堕檮鍔犲湪搴旂敤缁勪欢涓娿 璇峰弬鐓CModel::behaviors濡備綍鎸囧畾姝ゅ睘鎬у笺 CApplicationComponent
cookieMode string how to use cookie to store session ID. CHttpSession
cookieParams array the session cookie parameters. CHttpSession
count integer Returns the number of items in the session. CHttpSession
gCProbability integer the probability (percentage) that the gc (garbage collection) process is started on every session initialization, defaults to 1 meaning 1% chance. CHttpSession
isInitialized boolean 妫鏌ュ簲鐢ㄧ粍浠舵槸鍚﹀凡缁忓垵濮嬪寲銆 CApplicationComponent
isStarted boolean whether the session has started CHttpSession
iterator CHttpSessionIterator Returns an iterator for traversing the session variables. CHttpSession
keys array the list of session variable names CHttpSession
savePath string the current session save path, defaults to '/tmp'. CHttpSession
sessionID string the current session ID CHttpSession
sessionName string the current session name CHttpSession
timeout integer the number of seconds after which data will be seen as 'garbage' and cleaned up, defaults to 1440 seconds. CHttpSession
useCustomStorage boolean Returns a value indicating whether to use custom session storage. CHttpSession
useTransparentSessionID boolean whether transparent sid support is enabled or not, defaults to false. CHttpSession

鍏叡鏂规硶

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
__call() 濡傛灉绫讳腑娌℃湁璋冪殑鏂规硶鍚嶏紝鍒欒皟鐢ㄨ繖涓柟娉曘 CComponent
__get() 杩斿洖涓涓睘鎬у笺佷竴涓簨浠跺鐞嗙▼搴忓垪琛ㄦ垨涓涓涓哄悕绉般 CComponent
__isset() 妫鏌ヤ竴涓睘鎬ф槸鍚︿负null銆 CComponent
__set() 璁剧疆涓涓粍浠剁殑灞炴у笺 CComponent
__unset() 璁剧疆涓涓粍浠剁殑灞炴т负null銆 CComponent
add() Adds a session variable. CHttpSession
asa() 杩斿洖杩欎釜鍚嶅瓧鐨勮涓哄璞° CComponent
attachBehavior() 闄勫姞涓涓涓哄埌缁勪欢銆 CComponent
attachBehaviors() 闄勫姞涓涓涓哄垪琛ㄥ埌缁勪欢銆 CComponent
attachEventHandler() 涓轰簨浠堕檮鍔犱竴涓簨浠跺鐞嗙▼搴忋 CComponent
canGetProperty() 纭畾灞炴ф槸鍚﹀彲璇汇 CComponent
canSetProperty() 纭畾灞炴ф槸鍚﹀彲鍐欍 CComponent
clear() Removes all session variables CHttpSession
close() Ends the current session and store session data. CHttpSession
closeSession() Session close handler. CHttpSession
contains() CHttpSession
count() Returns the number of items in the session. CHttpSession
destroy() Frees all session variables and destroys all data registered to a session. CHttpSession
destroySession() Session destroy handler. CHttpSession
detachBehavior() 浠庣粍浠朵腑鍒嗙涓涓涓恒 CComponent
detachBehaviors() 浠庣粍浠朵腑鍒嗙鎵鏈夎涓恒 CComponent
detachEventHandler() 鍒嗙涓涓瓨鍦ㄧ殑浜嬩欢澶勭悊绋嬪簭銆 CComponent
disableBehavior() 绂佺敤涓涓檮鍔犺涓恒 CComponent
disableBehaviors() 绂佺敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
enableBehavior() 鍚敤涓涓檮鍔犺涓恒 CComponent
enableBehaviors() 鍚敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
evaluateExpression() 璁$畻涓涓狿HP琛ㄨ揪寮忥紝鎴栨牴鎹粍浠朵笂涓嬫枃鎵ц鍥炶皟銆 CComponent
gcSession() Session GC (garbage collection) handler. CHttpSession
get() Returns the session variable value with the session variable name. CHttpSession
getCookieMode() 杩斿洖how to use cookie to store session ID. Defaults to 'Allow'. CHttpSession
getCookieParams() 杩斿洖the session cookie parameters. CHttpSession
getCount() Returns the number of items in the session. CHttpSession
getEventHandlers() 杩斿洖涓涓簨浠剁殑闄勫姞澶勭悊绋嬪簭鍒楄〃銆 CComponent
getGCProbability() 杩斿洖the probability (percentage) that the gc (garbage collection) process is started on every session initialization, defaults to 1 meaning 1% chance. CHttpSession
getIsInitialized() 妫鏌ュ簲鐢ㄧ粍浠舵槸鍚﹀凡缁忓垵濮嬪寲銆 CApplicationComponent
getIsStarted() 妫鏌hether the session has started CHttpSession
getIterator() Returns an iterator for traversing the session variables. CHttpSession
getKeys() 杩斿洖the list of session variable names CHttpSession
getSavePath() 杩斿洖the current session save path, defaults to '/tmp'. CHttpSession
getSessionID() 杩斿洖the current session ID CHttpSession
getSessionName() 杩斿洖the current session name CHttpSession
getTimeout() 杩斿洖the number of seconds after which data will be seen as 'garbage' and cleaned up, defaults to 1440 seconds. CHttpSession
getUseCustomStorage() Returns a value indicating whether to use custom session storage. CHttpSession
getUseTransparentSessionID() 杩斿洖whether transparent sid support is enabled or not, defaults to false. CHttpSession
hasEvent() 纭畾涓涓簨浠舵槸鍚﹀畾涔夈 CComponent
hasEventHandler() 妫鏌ヤ簨浠舵槸鍚︽湁闄勫姞鐨勫鐞嗙▼搴忋 CComponent
hasProperty() 纭畾灞炴ф槸鍚﹁瀹氫箟銆 CComponent
init() Initializes the application component. CHttpSession
itemAt() Returns the session variable value with the session variable name. CHttpSession
offsetExists() This method is required by the interface ArrayAccess. CHttpSession
offsetGet() This method is required by the interface ArrayAccess. CHttpSession
offsetSet() This method is required by the interface ArrayAccess. CHttpSession
offsetUnset() This method is required by the interface ArrayAccess. CHttpSession
open() Starts the session if it has not started yet. CHttpSession
openSession() Session open handler. CHttpSession
raiseEvent() 鍙戣捣涓涓簨浠躲 CComponent
readSession() Session read handler. CHttpSession
regenerateID() Updates the current session id with a newly generated one . CHttpSession
remove() Removes a session variable. CHttpSession
setCookieMode() 璁剧疆how to use cookie to store session ID. Valid values include 'none', 'allow' and 'only'. CHttpSession
setCookieParams() Sets the session cookie parameters. CHttpSession
setGCProbability() 璁剧疆the probability (percentage) that the gc (garbage collection) process is started on every session initialization. CHttpSession
setSavePath() 璁剧疆the current session save path CHttpSession
setSessionID() 璁剧疆the session ID for the current session CHttpSession
setSessionName() 璁剧疆the session name for the current session, must be an alphanumeric string, defaults to PHPSESSID CHttpSession
setTimeout() 璁剧疆the number of seconds after which data will be seen as 'garbage' and cleaned up CHttpSession
setUseTransparentSessionID() 璁剧疆whether transparent sid support is enabled or not. CHttpSession
toArray() CHttpSession
writeSession() Session write handler. CHttpSession

灞炴ц缁

autoStart 灞炴
public boolean $autoStart;

whether the session should be automatically started when the session application component is initialized, defaults to true.

cookieMode 灞炴
public string getCookieMode()
public void setCookieMode(string $value)

how to use cookie to store session ID. Defaults to 'Allow'.

cookieParams 灞炴
public array getCookieParams()
public void setCookieParams(array $value)

the session cookie parameters.

count 灞炴 鍙
public integer getCount()

Returns the number of items in the session.

gCProbability 灞炴
public integer getGCProbability()
public void setGCProbability(integer $value)

the probability (percentage) that the gc (garbage collection) process is started on every session initialization, defaults to 1 meaning 1% chance.

isStarted 灞炴 鍙
public boolean getIsStarted()

whether the session has started

iterator 灞炴 鍙

Returns an iterator for traversing the session variables. This method is required by the interface IteratorAggregate.

keys 灞炴 鍙
public array getKeys()

the list of session variable names

savePath 灞炴
public string getSavePath()
public void setSavePath(string $value)

the current session save path, defaults to '/tmp'.

sessionID 灞炴
public string getSessionID()
public void setSessionID(string $value)

the current session ID

sessionName 灞炴
public string getSessionName()
public void setSessionName(string $value)

the current session name

timeout 灞炴
public integer getTimeout()
public void setTimeout(integer $value)

the number of seconds after which data will be seen as 'garbage' and cleaned up, defaults to 1440 seconds.

useCustomStorage 灞炴 鍙
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 openSession, closeSession, readSession, writeSession, destroySession, and gcSession are overridden in child class, because they will be used as the callback handlers. The default implementation always return false.

useTransparentSessionID 灞炴
public boolean getUseTransparentSessionID()
public void setUseTransparentSessionID(boolean $value)

whether transparent sid support is enabled or not, defaults to false.

鏂规硶璇︾粏

add() 鏂规硶
public void add(mixed $key, mixed $value)
$key mixed session variable name
$value mixed session variable value
婧愮爜锛 framework/web/CHttpSession.php#486 (鏄剧ず)
public function add($key,$value)
{
    
$_SESSION[$key]=$value;
}

Adds a session variable. Note, if the specified name already exists, the old value will be removed first.

clear() 鏂规硶
public void clear()
婧愮爜锛 framework/web/CHttpSession.php#511 (鏄剧ず)
public function clear()
{
    foreach(
array_keys($_SESSION) as $key)
        unset(
$_SESSION[$key]);
}

Removes all session variables

close() 鏂规硶
public void close()
婧愮爜锛 framework/web/CHttpSession.php#132 (鏄剧ず)
public function close()
{
    if(
session_id()!=='')
        @
session_write_close();
}

Ends the current session and store session data.

closeSession() 鏂规硶
public boolean closeSession()
{return} boolean whether session is closed successfully
婧愮爜锛 framework/web/CHttpSession.php#362 (鏄剧ず)
public function closeSession()
{
    return 
true;
}

Session close handler. This method should be overridden if useCustomStorage is set true. Do not call this method directly.

contains() 鏂规硶
public boolean contains(mixed $key)
$key mixed session variable name
{return} boolean whether there is the named session variable
婧愮爜锛 framework/web/CHttpSession.php#521 (鏄剧ず)
public function contains($key)
{
    return isset(
$_SESSION[$key]);
}

count() 鏂规硶
public integer count()
{return} integer number of items in the session.
婧愮爜锛 framework/web/CHttpSession.php#442 (鏄剧ず)
public function count()
{
    return 
$this->getCount();
}

Returns the number of items in the session. This method is required by Countable interface.

destroy() 鏂规硶
public void destroy()
婧愮爜锛 framework/web/CHttpSession.php#141 (鏄剧ず)
public function destroy()
{
    if(
session_id()!=='')
    {
        @
session_unset();
        @
session_destroy();
    }
}

Frees all session variables and destroys all data registered to a session.

destroySession() 鏂规硶
public boolean destroySession(string $id)
$id string session ID
{return} boolean whether session is destroyed successfully
婧愮爜锛 framework/web/CHttpSession.php#399 (鏄剧ず)
public function destroySession($id)
{
    return 
true;
}

Session destroy handler. This method should be overridden if useCustomStorage is set true. Do not call this method directly.

gcSession() 鏂规硶
public boolean gcSession(integer $maxLifetime)
$maxLifetime integer the number of seconds after which data will be seen as 'garbage' and cleaned up.
{return} boolean whether session is GCed successfully
婧愮爜锛 framework/web/CHttpSession.php#411 (鏄剧ず)
public function gcSession($maxLifetime)
{
    return 
true;
}

Session GC (garbage collection) handler. This method should be overridden if useCustomStorage is set true. Do not call this method directly.

get() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.2锛
public mixed get(mixed $key, mixed $defaultValue=NULL)
$key mixed the session variable name
$defaultValue mixed the default value to be returned when the session variable does not exist.
{return} mixed the session variable value, or $defaultValue if the session variable does not exist.
婧愮爜锛 framework/web/CHttpSession.php#464 (鏄剧ず)
public function get($key,$defaultValue=null)
{
    return isset(
$_SESSION[$key]) ? $_SESSION[$key] : $defaultValue;
}

Returns the session variable value with the session variable name. This method is very similar to itemAt and offsetGet, except that it will return $defaultValue if the session variable does not exist.

getCookieMode() 鏂规硶
public string getCookieMode()
{return} string how to use cookie to store session ID. Defaults to 'Allow'.
婧愮爜锛 framework/web/CHttpSession.php#252 (鏄剧ず)
public function getCookieMode()
{
    if(
ini_get('session.use_cookies')==='0')
        return 
'none';
    else if(
ini_get('session.use_only_cookies')==='0')
        return 
'allow';
    else
        return 
'only';
}

getCookieParams() 鏂规硶
public array getCookieParams()
{return} array the session cookie parameters.
婧愮爜锛 framework/web/CHttpSession.php#226 (鏄剧ず)
public function getCookieParams()
{
    return 
session_get_cookie_params();
}

getCount() 鏂规硶
public integer getCount()
{return} integer the number of session variables
婧愮爜锛 framework/web/CHttpSession.php#432 (鏄剧ず)
public function getCount()
{
    return 
count($_SESSION);
}

Returns the number of items in the session.

getGCProbability() 鏂规硶
public integer getGCProbability()
{return} integer the probability (percentage) that the gc (garbage collection) process is started on every session initialization, defaults to 1 meaning 1% chance.
婧愮爜锛 framework/web/CHttpSession.php#289 (鏄剧ず)
public function getGCProbability()
{
    return (int)
ini_get('session.gc_probability');
}

getIsStarted() 鏂规硶
public boolean getIsStarted()
{return} boolean whether the session has started
婧愮爜锛 framework/web/CHttpSession.php#153 (鏄剧ず)
public function getIsStarted()
{
    return 
session_id()!=='';
}

getIterator() 鏂规硶
public CHttpSessionIterator getIterator()
{return} CHttpSessionIterator an iterator for traversing the session variables.
婧愮爜锛 framework/web/CHttpSession.php#423 (鏄剧ず)
public function getIterator()
{
    return new 
CHttpSessionIterator;
}

Returns an iterator for traversing the session variables. This method is required by the interface IteratorAggregate.

getKeys() 鏂规硶
public array getKeys()
{return} array the list of session variable names
婧愮爜锛 framework/web/CHttpSession.php#450 (鏄剧ず)
public function getKeys()
{
    return 
array_keys($_SESSION);
}

getSavePath() 鏂规硶
public string getSavePath()
{return} string the current session save path, defaults to '/tmp'.
婧愮爜锛 framework/web/CHttpSession.php#204 (鏄剧ず)
public function getSavePath()
{
    return 
session_save_path();
}

getSessionID() 鏂规硶
public string getSessionID()
{return} string the current session ID
婧愮爜锛 framework/web/CHttpSession.php#161 (鏄剧ず)
public function getSessionID()
{
    return 
session_id();
}

getSessionName() 鏂规硶
public string getSessionName()
{return} string the current session name
婧愮爜锛 framework/web/CHttpSession.php#188 (鏄剧ず)
public function getSessionName()
{
    return 
session_name();
}

getTimeout() 鏂规硶
public integer getTimeout()
{return} integer the number of seconds after which data will be seen as 'garbage' and cleaned up, defaults to 1440 seconds.
婧愮爜锛 framework/web/CHttpSession.php#330 (鏄剧ず)
public function getTimeout()
{
    return (int)
ini_get('session.gc_maxlifetime');
}

getUseCustomStorage() 鏂规硶
public boolean getUseCustomStorage()
{return} boolean whether to use custom storage.
婧愮爜锛 framework/web/CHttpSession.php#102 (鏄剧ず)
public function getUseCustomStorage()
{
    return 
false;
}

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 openSession, closeSession, readSession, writeSession, destroySession, and gcSession are overridden in child class, because they will be used as the callback handlers. The default implementation always return false.

getUseTransparentSessionID() 鏂规硶
public boolean getUseTransparentSessionID()
{return} boolean whether transparent sid support is enabled or not, defaults to false.
婧愮爜锛 framework/web/CHttpSession.php#314 (鏄剧ず)
public function getUseTransparentSessionID()
{
    return 
ini_get('session.use_trans_sid')==1;
}

init() 鏂规硶
public void init()
婧愮爜锛 framework/web/CHttpSession.php#85 (鏄剧ず)
public function init()
{
    
parent::init();
    if(
$this->autoStart)
        
$this->open();
    
register_shutdown_function(array($this,'close'));
}

Initializes the application component. This method is required by IApplicationComponent and is invoked by application.

itemAt() 鏂规硶
public mixed itemAt(mixed $key)
$key mixed the session variable name
{return} mixed the session variable value, null if no such variable exists
婧愮爜锛 framework/web/CHttpSession.php#475 (鏄剧ず)
public function itemAt($key)
{
    return isset(
$_SESSION[$key]) ? $_SESSION[$key] : null;
}

Returns the session variable value with the session variable name. This method is exactly the same as offsetGet.

offsetExists() 鏂规硶
public boolean offsetExists(mixed $offset)
$offset mixed the offset to check on
{return} boolean
婧愮爜锛 framework/web/CHttpSession.php#539 (鏄剧ず)
public function offsetExists($offset)
{
    return isset(
$_SESSION[$offset]);
}

This method is required by the interface ArrayAccess.

offsetGet() 鏂规硶
public mixed offsetGet(integer $offset)
$offset integer the offset to retrieve element.
{return} mixed the element at the offset, null if no element is found at the offset
婧愮爜锛 framework/web/CHttpSession.php#549 (鏄剧ず)
public function offsetGet($offset)
{
    return isset(
$_SESSION[$offset]) ? $_SESSION[$offset] : null;
}

This method is required by the interface ArrayAccess.

offsetSet() 鏂规硶
public void offsetSet(integer $offset, mixed $item)
$offset integer the offset to set element
$item mixed the element value
婧愮爜锛 framework/web/CHttpSession.php#559 (鏄剧ず)
public function offsetSet($offset,$item)
{
    
$_SESSION[$offset]=$item;
}

This method is required by the interface ArrayAccess.

offsetUnset() 鏂规硶
public void offsetUnset(mixed $offset)
$offset mixed the offset to unset element
婧愮爜锛 framework/web/CHttpSession.php#568 (鏄剧ず)
public function offsetUnset($offset)
{
    unset(
$_SESSION[$offset]);
}

This method is required by the interface ArrayAccess.

open() 鏂规硶
public void open()
婧愮爜锛 framework/web/CHttpSession.php#110 (鏄剧ず)
public function open()
{
    if(
$this->getUseCustomStorage())
        @
session_set_save_handler(array($this,'openSession'),array($this,'closeSession'),array($this,'readSession'),array($this,'writeSession'),array($this,'destroySession'),array($this,'gcSession'));

    @
session_start();
    if(
YII_DEBUG && session_id()=='')
    {
        
$message=Yii::t('yii','Failed to start session.');
        if(
function_exists('error_get_last'))
        {
            
$error=error_get_last();
            if(isset(
$error['message']))
                
$message=$error['message'];
        }
        
Yii::log($messageCLogger::LEVEL_WARNING'system.web.CHttpSession');
    }
}

Starts the session if it has not started yet.

openSession() 鏂规硶
public boolean openSession(string $savePath, string $sessionName)
$savePath string session save path
$sessionName string session name
{return} boolean whether session is opened successfully
婧愮爜锛 framework/web/CHttpSession.php#351 (鏄剧ず)
public function openSession($savePath,$sessionName)
{
    return 
true;
}

Session open handler. This method should be overridden if useCustomStorage is set true. Do not call this method directly.

readSession() 鏂规硶
public string readSession(string $id)
$id string session ID
{return} string the session data
婧愮爜锛 framework/web/CHttpSession.php#374 (鏄剧ず)
public function readSession($id)
{
    return 
'';
}

Session read handler. This method should be overridden if useCustomStorage is set true. Do not call this method directly.

regenerateID() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.8锛
public void regenerateID(boolean $deleteOldSession=false)
$deleteOldSession boolean Whether to delete the old associated session file or not.
婧愮爜锛 framework/web/CHttpSession.php#180 (鏄剧ず)
public function regenerateID($deleteOldSession=false)
{
    
session_regenerate_id($deleteOldSession);
}

Updates the current session id with a newly generated one . Please refer to http://php.net/session_regenerate_id for more details.

remove() 鏂规硶
public mixed remove(mixed $key)
$key mixed the name of the session variable to be removed
{return} mixed the removed value, null if no such session variable.
婧愮爜锛 framework/web/CHttpSession.php#496 (鏄剧ず)
public function remove($key)
{
    if(isset(
$_SESSION[$key]))
    {
        
$value=$_SESSION[$key];
        unset(
$_SESSION[$key]);
        return 
$value;
    }
    else
        return 
null;
}

Removes a session variable.

setCookieMode() 鏂规硶
public void setCookieMode(string $value)
$value string how to use cookie to store session ID. Valid values include 'none', 'allow' and 'only'.
婧愮爜锛 framework/web/CHttpSession.php#265 (鏄剧ず)
public function setCookieMode($value)
{
    if(
$value==='none')
    {
        
ini_set('session.use_cookies','0');
        
ini_set('session.use_only_cookies','0');
    }
    else if(
$value==='allow')
    {
        
ini_set('session.use_cookies','1');
        
ini_set('session.use_only_cookies','0');
    }
    else if(
$value==='only')
    {
        
ini_set('session.use_cookies','1');
        
ini_set('session.use_only_cookies','1');
    }
    else
        throw new 
CException(Yii::t('yii','CHttpSession.cookieMode can only be "none", "allow" or "only".'));
}

setCookieParams() 鏂规硶
public void setCookieParams(array $value)
$value array cookie parameters, valid keys include: lifetime, path, domain, secure.
婧愮爜锛 framework/web/CHttpSession.php#238 (鏄剧ず)
public function setCookieParams($value)
{
    
$data=session_get_cookie_params();
    
extract($data);
    
extract($value);
    if(isset(
$httponly))
        
session_set_cookie_params($lifetime,$path,$domain,$secure,$httponly);
    else
        
session_set_cookie_params($lifetime,$path,$domain,$secure);
}

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.

setGCProbability() 鏂规硶
public void setGCProbability(integer $value)
$value integer the probability (percentage) that the gc (garbage collection) process is started on every session initialization.
婧愮爜锛 framework/web/CHttpSession.php#298 (鏄剧ず)
public function setGCProbability($value)
{
    
$value=(int)$value;
    if(
$value>=&& $value<=100)
    {
        
ini_set('session.gc_probability',$value);
        
ini_set('session.gc_divisor','100');
    }
    else
        throw new 
CException(Yii::t('yii','CHttpSession.gcProbability "{value}" is invalid. It must be an integer between 0 and 100.',
            array(
'{value}'=>$value)));
}

setSavePath() 鏂规硶
public void setSavePath(string $value)
$value string the current session save path
婧愮爜锛 framework/web/CHttpSession.php#213 (鏄剧ず)
public function setSavePath($value)
{
    if(
is_dir($value))
        
session_save_path($value);
    else
        throw new 
CException(Yii::t('yii','CHttpSession.savePath "{path}" is not a valid directory.',
            array(
'{path}'=>$value)));
}

setSessionID() 鏂规硶
public void setSessionID(string $value)
$value string the session ID for the current session
婧愮爜锛 framework/web/CHttpSession.php#169 (鏄剧ず)
public function setSessionID($value)
{
    
session_id($value);
}

setSessionName() 鏂规硶
public void setSessionName(string $value)
$value string the session name for the current session, must be an alphanumeric string, defaults to PHPSESSID
婧愮爜锛 framework/web/CHttpSession.php#196 (鏄剧ず)
public function setSessionName($value)
{
    
session_name($value);
}

setTimeout() 鏂规硶
public void setTimeout(integer $value)
$value integer the number of seconds after which data will be seen as 'garbage' and cleaned up
婧愮爜锛 framework/web/CHttpSession.php#338 (鏄剧ず)
public function setTimeout($value)
{
    
ini_set('session.gc_maxlifetime',$value);
}

setUseTransparentSessionID() 鏂规硶
public void setUseTransparentSessionID(boolean $value)
$value boolean whether transparent sid support is enabled or not.
婧愮爜锛 framework/web/CHttpSession.php#322 (鏄剧ず)
public function setUseTransparentSessionID($value)
{
    
ini_set('session.use_trans_sid',$value?'1':'0');
}

toArray() 鏂规硶
public array toArray()
{return} array the list of all session variables in array
婧愮爜锛 framework/web/CHttpSession.php#529 (鏄剧ず)
public function toArray()
{
    return 
$_SESSION;
}

writeSession() 鏂规硶
public boolean writeSession(string $id, string $data)
$id string session ID
$data string session data
{return} boolean whether session write is successful
婧愮爜锛 framework/web/CHttpSession.php#387 (鏄剧ず)
public function writeSession($id,$data)
{
    return 
true;
}

Session write handler. This method should be overridden if useCustomStorage is set true. Do not call this method directly.

Copyright © 2008-2011 by Yii Software LLC
All Rights Reserved.