PRADO Component Framework for PHP 5
  • Home
  • About
  • Testimonials
  • Demos
  • Download
  • Documentation
  • Forum
  • Development
  • Tutorials
  • Class Docs
  • API Manual
  • Wiki

Packages

  • None
  • System
    • Caching
    • Collections
    • Data
      • ActiveRecord
        • Relations
        • Scaffold
          • InputBuilder
      • Commom
        • Sqlite
      • Common
        • Mssql
        • Mysql
        • Oracle
        • Pgsql
        • Sqlite
      • DataGateway
      • SqlMap
        • Configuration
        • Statements
    • Exceptions
    • I18N
    • IO
    • Security
    • Util
    • Web
      • Javascripts
      • Services
      • UI
        • ActiveControls
        • WebControls
    • Xml
  • Wsat
    • pages
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo

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
Extended by TApplicationComponent
Extended by THttpSession implements IteratorAggregate, ArrayAccess, Countable, IModule

Direct known subclasses

TCacheHttpSession
Package: System\Web
Copyright: 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
Methods summary
public string
# getID( )

Returns

string
id of this module

Implementation of

IModule::getID()
public
# setID( string $value )

Parameters

$value
string
id of this module

Implementation of

IModule::setID()
public
# init( TXmlElement $config )

Initializes the module. This method is required by IModule. If AutoStart is true, the session will be started.

Initializes the module. This method is required by IModule. If AutoStart is true, the session will be started.

Parameters

$config
TXmlElement
module configuration

Implementation of

IModule::init()
public
# open( )

Starts the session if it has not started yet.

Starts the session if it has not started yet.

public
# close( )

Ends the current session and store session data.

Ends the current session and store session data.

public
# destroy( )

Destroys all data registered to a session.

Destroys all data registered to a session.

public string
# regenerate( boolean $deleteOld = false )

Update the current session id with a newly generated one

Update the current session id with a newly generated one

Parameters

$deleteOld
boolean
$deleteOld Whether to delete the old associated session or not.

Returns

string
old session id

Link

http://php.net/manual/en/function.session-regenerate-id.php
public boolean
# getIsStarted( )

Returns

boolean
whether the session has started
public string
# getSessionID( )

Returns

string
the current session ID
public
# setSessionID( string $value )

Parameters

$value
string
the session ID for the current session

Throws

TInvalidOperationException
if session is started already
public string
# getSessionName( )

Returns

string
the current session name
public
# setSessionName( string $value )

Parameters

$value
string
the session name for the current session, must be an alphanumeric string, defaults to PHPSESSID

Throws

TInvalidOperationException
if session is started already
public string
# getSavePath( )

Returns

string
the current session save path, defaults to '/tmp'.
public
# setSavePath( string $value )

Parameters

$value
string
the current session save path

Throws

TInvalidOperationException
if session is started already
public boolean
# getUseCustomStorage( )

Returns

boolean
whether to use user-specified handlers to store session data. Defaults to false.
public
# setUseCustomStorage( boolean $value )

Parameters

$value
boolean
whether to use user-specified handlers to store session data. If true, make sure the methods THttpSession::_open(), THttpSession::_close(), THttpSession::_read(), THttpSession::_write(), THttpSession::_destroy(), and THttpSession::_gc() are overridden in child class, because they will be used as the callback handlers.
public THttpCookie
# getCookie( )

Returns

THttpCookie
cookie that will be used to store session ID
public THttpSessionCookieMode
# getCookieMode( )

Returns

THttpSessionCookieMode
how to use cookie to store session ID. Defaults to THttpSessionCookieMode::Allow.
public
# setCookieMode( THttpSessionCookieMode $value )

Parameters

$value
THttpSessionCookieMode
how to use cookie to store session ID

Throws

TInvalidOperationException
if session is started already
public boolean
# getAutoStart( )

Returns

boolean
whether the session should be automatically started when the session module is initialized, defaults to false.
public
# setAutoStart( boolean $value )

Parameters

$value
boolean
whether the session should be automatically started when the session module is initialized, defaults to false.

Throws

TInvalidOperationException
if session is started already
public integer
# getGCProbability( )

Returns

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

Parameters

$value
integer
the probability (percentage) that the gc (garbage collection) process is started on every session initialization.

Throws

TInvalidOperationException
if session is started already
TInvalidDataValueException
if the value is beyond [0,100].
public boolean
# getUseTransparentSessionID( )

Returns

boolean
whether transparent sid support is enabled or not, defaults to false.
public
# setUseTransparentSessionID( boolean $value )

Parameters

$value
boolean
whether transparent sid support is enabled or not.
public integer
# getTimeout( )

Returns

integer
the number of seconds after which data will be seen as 'garbage' and cleaned up, defaults to 1440 seconds.
public
# setTimeout( integer $value )

Parameters

$value
integer
the number of seconds after which data will be seen as 'garbage' and cleaned up

Throws

TInvalidOperationException
if session is started already
public boolean
# _open( string $savePath, string $sessionName )

Session open handler. This method should be overridden if setUseCustomStorage UseCustomStorage is set true.

Session open handler. This method should be overridden if setUseCustomStorage UseCustomStorage is set true.

Parameters

$savePath
string
session save path
$sessionName
string
session name

Returns

boolean
whether session is opened successfully
public boolean
# _close( )

Session close handler. This method should be overridden if setUseCustomStorage UseCustomStorage is set true.

Session close handler. This method should be overridden if setUseCustomStorage UseCustomStorage is set true.

Returns

boolean
whether session is closed successfully
public string
# _read( string $id )

Session read handler. This method should be overridden if setUseCustomStorage UseCustomStorage is set true.

Session read handler. This method should be overridden if setUseCustomStorage UseCustomStorage is set true.

Parameters

$id
string
session ID

Returns

string
the session data
public boolean
# _write( string $id, string $data )

Session write handler. This method should be overridden if setUseCustomStorage UseCustomStorage is set true.

Session write handler. This method should be overridden if setUseCustomStorage UseCustomStorage is set true.

Parameters

$id
string
session ID
$data
string
session data

Returns

boolean
whether session write is successful
public boolean
# _destroy( string $id )

Session destroy handler. This method should be overridden if setUseCustomStorage UseCustomStorage is set true.

Session destroy handler. This method should be overridden if setUseCustomStorage UseCustomStorage is set true.

Parameters

$id
string
session ID

Returns

boolean
whether session is destroyed successfully
public boolean
# _gc( integer $maxLifetime )

Session GC (garbage collection) handler. This method should be overridden if setUseCustomStorage UseCustomStorage is set true.

Session GC (garbage collection) handler. This method should be overridden if setUseCustomStorage UseCustomStorage is set true.

Parameters

$maxLifetime
integer
the number of seconds after which data will be seen as 'garbage' and cleaned up.

Returns

boolean
whether session is GCed successfully
public TSessionIterator
# getIterator( )

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

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

Returns

TSessionIterator
an iterator for traversing the session variables.

Implementation of

IteratorAggregate::getIterator()
public integer
# getCount( )

Returns

integer
the number of session variables
public integer
# count( )

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

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

Returns

integer
number of items in the session.

Implementation of

Countable::count()
public array
# getKeys( )

Returns

array
the list of session variable names
public mixed
# itemAt( mixed $key )

Returns the session variable value with the session variable name. This method is exactly the same as THttpSession::offsetGet().

Returns the session variable value with the session variable name. This method is exactly the same as THttpSession::offsetGet().

Parameters

$key
mixed
the session variable name

Returns

mixed
the session variable value, null if no such variable exists
public
# add( mixed $key, mixed $value )

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

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

Parameters

$key
mixed
session variable name
$value
mixed
session variable value
public mixed
# remove( mixed $key )

Removes a session variable.

Removes a session variable.

Parameters

$key
mixed
the name of the session variable to be removed

Returns

mixed
the removed value, null if no such session variable.
public
# clear( )

Removes all session variables

Removes all session variables

public boolean
# contains( mixed $key )

Parameters

$key
mixed
session variable name

Returns

boolean
whether there is the named session variable
public array
# toArray( )

Returns

array
the list of all session variables in array
public boolean
# offsetExists( mixed $offset )

This method is required by the interface ArrayAccess.

This method is required by the interface ArrayAccess.

Parameters

$offset
mixed
the offset to check on

Returns

boolean

Implementation of

ArrayAccess::offsetExists()
public mixed
# offsetGet( integer $offset )

This method is required by the interface ArrayAccess.

This method is required by the interface ArrayAccess.

Parameters

$offset
integer
the offset to retrieve element.

Returns

mixed
the element at the offset, null if no element is found at the offset

Implementation of

ArrayAccess::offsetGet()
public
# offsetSet( integer $offset, mixed $item )

This method is required by the interface ArrayAccess.

This method is required by the interface ArrayAccess.

Parameters

$offset
integer
the offset to set element
$item
mixed
the element value

Implementation of

ArrayAccess::offsetSet()
public
# offsetUnset( mixed $offset )

This method is required by the interface ArrayAccess.

This method is required by the interface ArrayAccess.

Parameters

$offset
mixed
the offset to unset element

Implementation of

ArrayAccess::offsetUnset()
Methods inherited from TApplicationComponent
getApplication(), getRequest(), getResponse(), getService(), getSession(), getUser(), publishAsset(), publishFilePath()
Methods inherited from TComponent
__call(), __construct(), __destruct(), __get(), __isset(), __set(), __sleep(), __unset(), __wakeup(), addParsedObject(), asa(), attachBehavior(), attachBehaviors(), attachClassBehavior(), attachEventHandler(), canGetProperty(), canSetProperty(), clearBehaviors(), createdOnTemplate(), detachBehavior(), detachBehaviors(), detachClassBehavior(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), evaluateStatements(), fxAttachClassBehavior(), fxDetachClassBehavior(), getAutoGlobalListen(), getBehaviorsEnabled(), getClassHierarchy(), getEventHandlers(), getListeningToGlobalEvents(), getSubProperty(), hasEvent(), hasEventHandler(), hasProperty(), isa(), listen(), raiseEvent(), setSubProperty(), unlisten()
Constants inherited from TComponent
GLOBAL_RAISE_EVENT_LISTENER
Terms of Service | Contact Us
PRADO v3.2.4 API Manual API documentation generated by ApiGen 2.8.0
Copyright © 2006-2014 by the PRADO Group.
Powered by PRADO