PHP 클래스 Prado\Web\THttpSession

THttpSession provides session-level data management and the related configurations. To start the session, call {@link open}; to complete and send out session data, call {@link close}; to destroy the session, call {@link 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: {@link setAutoStart AutoStart}, {@link setCookieMode CookieMode}, {@link setSavePath SavePath}, {@link setUseCustomStorage UseCustomStorage}, {@link setGCProbability GCProbability}, {@link 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 {@link _open}, {@link _close}, {@link _read}, {@link _write}, {@link _destroy} and {@link _gc} and set {@link setUseCustomStorage UseCustomStorage} to true. Then, the session data will be stored using the above methods. By default, THttpSession is registered with {@link TApplication} as the request module. It can be accessed via {@link TApplication::getSession()}. THttpSession may be configured in application configuration file as follows, where {@link getSessionName SessionName}, {@link getSavePath SavePath}, {@link getCookieMode CookieMode}, {@link getUseCustomStorage UseCustomStorage}, {@link getAutoStart AutoStart}, {@link getGCProbability GCProbability}, {@link getUseTransparentSessionID UseTransparentSessionID} and {@link getTimeout TimeOut} 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,
부터: 3.0
저자: Qiang Xue ([email protected])
상속: extends Prado\TApplicationComponent, implements IteratorAggregate, implements ArrayAccess, implements Countable, implements Prado\IModule
파일 보기 프로젝트 열기: pradosoft/prado 1 사용 예제들

공개 메소드들

메소드 설명
_close ( ) : boolean Session close handler.
_destroy ( $id ) : boolean Session destroy handler.
_gc ( $maxLifetime ) : boolean Session GC (garbage collection) handler.
_open ( $savePath, $sessionName ) : boolean Session open handler.
_read ( $id ) : string Session read handler.
_write ( $id, $data ) : boolean Session write handler.
add ( $key, $value ) Adds a session variable.
clear ( ) Removes all session variables
close ( ) Ends the current session and store session data.
contains ( $key ) : boolean
count ( ) : integer Returns the number of items in the session.
destroy ( ) Destroys all data registered to a session.
getAutoStart ( ) : boolean
getCookie ( ) : THttpCookie
getCookieMode ( ) : THttpSessionCookieMode
getCount ( ) : integer
getGCProbability ( ) : integer
getID ( ) : string
getIsStarted ( ) : boolean
getIterator ( ) : TSessionIterator Returns an iterator for traversing the session variables.
getKeys ( ) : array
getSavePath ( ) : string
getSessionID ( ) : string
getSessionName ( ) : string
getTimeout ( ) : integer
getUseCustomStorage ( ) : boolean
getUseTransparentSessionID ( ) : boolean
init ( $config ) Initializes the module.
itemAt ( $key ) : mixed Returns the session variable value with the session variable name.
offsetExists ( $offset ) : boolean This method is required by the interface \ArrayAccess.
offsetGet ( $offset ) : mixed This method is required by the interface \ArrayAccess.
offsetSet ( $offset, $item ) This method is required by the interface \ArrayAccess.
offsetUnset ( $offset ) This method is required by the interface \ArrayAccess.
open ( ) Starts the session if it has not started yet.
regenerate ( boolean $deleteOld = false ) : string Update the current session id with a newly generated one
remove ( $key ) : mixed Removes a session variable.
setAutoStart ( $value )
setCookieMode ( $value )
setGCProbability ( $value )
setID ( $value )
setSavePath ( $value )
setSessionID ( $value )
setSessionName ( $value )
setTimeout ( $value )
setUseCustomStorage ( $value )
setUseTransparentSessionID ( $value )
toArray ( ) : array

메소드 상세

_close() 공개 메소드

This method should be overridden if {@link setUseCustomStorage UseCustomStorage} is set true.
public _close ( ) : boolean
리턴 boolean whether session is closed successfully

_destroy() 공개 메소드

This method should be overridden if {@link setUseCustomStorage UseCustomStorage} is set true.
public _destroy ( $id ) : boolean
리턴 boolean whether session is destroyed successfully

_gc() 공개 메소드

This method should be overridden if {@link setUseCustomStorage UseCustomStorage} is set true.
public _gc ( $maxLifetime ) : boolean
리턴 boolean whether session is GCed successfully

_open() 공개 메소드

This method should be overridden if {@link setUseCustomStorage UseCustomStorage} is set true.
public _open ( $savePath, $sessionName ) : boolean
리턴 boolean whether session is opened successfully

_read() 공개 메소드

This method should be overridden if {@link setUseCustomStorage UseCustomStorage} is set true.
public _read ( $id ) : string
리턴 string the session data

_write() 공개 메소드

This method should be overridden if {@link setUseCustomStorage UseCustomStorage} is set true.
public _write ( $id, $data ) : boolean
리턴 boolean whether session write is successful

add() 공개 메소드

Note, if the specified name already exists, the old value will be removed first.
public add ( $key, $value )

clear() 공개 메소드

Removes all session variables
public clear ( )

close() 공개 메소드

Ends the current session and store session data.
public close ( )

contains() 공개 메소드

public contains ( $key ) : boolean
리턴 boolean whether there is the named session variable

count() 공개 메소드

This method is required by \Countable interface.
public count ( ) : integer
리턴 integer number of items in the session.

destroy() 공개 메소드

Destroys all data registered to a session.
public destroy ( )

getAutoStart() 공개 메소드

public getAutoStart ( ) : boolean
리턴 boolean whether the session should be automatically started when the session module is initialized, defaults to false.

getCookie() 공개 메소드

public getCookie ( ) : THttpCookie
리턴 THttpCookie cookie that will be used to store session ID

getCookieMode() 공개 메소드

public getCookieMode ( ) : THttpSessionCookieMode
리턴 THttpSessionCookieMode how to use cookie to store session ID. Defaults to THttpSessionCookieMode::Allow.

getCount() 공개 메소드

public getCount ( ) : integer
리턴 integer the number of session variables

getGCProbability() 공개 메소드

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

getID() 공개 메소드

public getID ( ) : string
리턴 string id of this module

getIsStarted() 공개 메소드

public getIsStarted ( ) : boolean
리턴 boolean whether the session has started

getIterator() 공개 메소드

This method is required by the interface \IteratorAggregate.
public getIterator ( ) : TSessionIterator
리턴 TSessionIterator an iterator for traversing the session variables.

getKeys() 공개 메소드

public getKeys ( ) : array
리턴 array the list of session variable names

getSavePath() 공개 메소드

public getSavePath ( ) : string
리턴 string the current session save path, defaults to '/tmp'.

getSessionID() 공개 메소드

public getSessionID ( ) : string
리턴 string the current session ID

getSessionName() 공개 메소드

public getSessionName ( ) : string
리턴 string the current session name

getTimeout() 공개 메소드

public getTimeout ( ) : integer
리턴 integer the number of seconds after which data will be seen as 'garbage' and cleaned up, defaults to 1440 seconds.

getUseCustomStorage() 공개 메소드

public getUseCustomStorage ( ) : boolean
리턴 boolean whether to use user-specified handlers to store session data. Defaults to false.

getUseTransparentSessionID() 공개 메소드

public getUseTransparentSessionID ( ) : boolean
리턴 boolean whether transparent sid support is enabled or not, defaults to false.

init() 공개 메소드

This method is required by IModule. If AutoStart is true, the session will be started.
public init ( $config )

itemAt() 공개 메소드

This method is exactly the same as {@link offsetGet}.
public itemAt ( $key ) : mixed
리턴 mixed the session variable value, null if no such variable exists

offsetExists() 공개 메소드

This method is required by the interface \ArrayAccess.
public offsetExists ( $offset ) : boolean
리턴 boolean

offsetGet() 공개 메소드

This method is required by the interface \ArrayAccess.
public offsetGet ( $offset ) : mixed
리턴 mixed the element at the offset, null if no element is found at the offset

offsetSet() 공개 메소드

This method is required by the interface \ArrayAccess.
public offsetSet ( $offset, $item )

offsetUnset() 공개 메소드

This method is required by the interface \ArrayAccess.
public offsetUnset ( $offset )

open() 공개 메소드

Starts the session if it has not started yet.
public open ( )

regenerate() 공개 메소드

Update the current session id with a newly generated one
public regenerate ( boolean $deleteOld = false ) : string
$deleteOld boolean Whether to delete the old associated session or not.
리턴 string old session id

remove() 공개 메소드

Removes a session variable.
public remove ( $key ) : mixed
리턴 mixed the removed value, null if no such session variable.

setAutoStart() 공개 메소드

public setAutoStart ( $value )

setCookieMode() 공개 메소드

public setCookieMode ( $value )

setGCProbability() 공개 메소드

public setGCProbability ( $value )

setID() 공개 메소드

public setID ( $value )

setSavePath() 공개 메소드

public setSavePath ( $value )

setSessionID() 공개 메소드

public setSessionID ( $value )

setSessionName() 공개 메소드

public setSessionName ( $value )

setTimeout() 공개 메소드

public setTimeout ( $value )

setUseCustomStorage() 공개 메소드

public setUseCustomStorage ( $value )

setUseTransparentSessionID() 공개 메소드

public setUseTransparentSessionID ( $value )

toArray() 공개 메소드

public toArray ( ) : array
리턴 array the list of all session variables in array