HTTP_Session
[ class tree: HTTP_Session ] [ index: HTTP_Session ] [ all elements ]

Class: HTTP_Session

Source Location: /HTTP_Session-0.5.4/Session.php

Class Overview


Class for managing HTTP sessions


Author(s):

Version:

  • Release: @package_version@

Copyright:

  • 1997-2005 The PHP Group

Methods


Inherited Variables

Inherited Methods


Class Details

[line 104]
Class for managing HTTP sessions

Provides access to session-state values as well as session-level settings and lifetime management methods. Based on the standart PHP session handling mechanism it provides for you more advanced features such as database container, idle and expire timeouts, etc.

Expample 1:

  1.  // Setting some options and detecting of a new session
  2.  HTTP_Session::setCookieless(false);
  3.  HTTP_Session::start('MySessionID');
  4.  HTTP_Session::set('variable''Tet string');
  5.  if (HTTP_Session::isNew()) {
  6.      echo('new session was created with the current request');
  7.      $visitors++; // Increase visitors count
  8.  }
  9.  
  10.  //HTTP_Session::regenerateId();

Example 2:

  1.  // Using database container

Example 3:

  1.  // Setting timeouts
  2.  HTTP_Session::setExpire(time(+ 60 * 60)// expires in one hour
  3.  HTTP_Session::setIdle(time()+ 10 * 60);    // idles in ten minutes
  4.  if (HTTP_Session::isExpired()) {
  5.      // expired
  6.      echo('Your session is expired!');
  7.      HTTP_Session::destroy();
  8.  }
  9.  if (HTTP_Session::isIdle()) {
  10.      // idle
  11.      echo('You've been idle for too long!');
  12.      HTTP_Session::destroy();
  13.  }
  14.  HTTP_Session::updateIdle();



[ Top ]


Method Detail

clear   [line 266]

void clear( )

Free all session variables
  • Todo: TODO Save expire and idle timestamps?
  • Access: public

[ Top ]

destroy   [line 203]

void destroy( )

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

This method resets the $_SESSION variable and destroys all of the data associated with the current session in its storage (file or DB). It forces new session to be started after this method is called. It does not unset the session cookie.


[ Top ]

get   [line 528]

mixed &get( string $name, [mixed $default = null])

Returns session variable
  • Return: Value of a variable
  • Access: public

Parameters:

string   $name   —  Name of a variable
mixed   $default   —  Default value of a variable if not set

[ Top ]

getLocal   [line 579]

mixed &getLocal( string $name, [mixed $default = null])

Returns local variable of a script

Two scripts can have local variables with the same names

  • Return: Value of a local variable
  • Access: public

Parameters:

string   $name   —  Name of a variable
mixed   $default   —  Default value of a variable if not set

[ Top ]

id   [line 320]

string id( [string $id = null])

Sets new ID of a session
  • Return: Previous ID of a session
  • See: session_id()
  • Access: public

Parameters:

string   $id   —  New ID of a sesion

[ Top ]

isExpired   [line 397]

boolean isExpired( )

Check if session is expired
  • Access: public

[ Top ]

isIdle   [line 413]

boolean isIdle( )

Check if session is idle
  • Access: public

[ Top ]

isNew   [line 468]

boolean isNew( )

Gets a value indicating whether the session was created with the current request

You MUST call this method only after you have started the session with the HTTP_Session::start() method.

  • Return: true if the session was created with the current request, false otherwise
  • Access: public

[ Top ]

is_set   [line 563]

bool is_set( $name)

Checks if a session variable is set
  • Access: public

Parameters:

   $name   — 

[ Top ]

localName   [line 624]

string localName( [string $name = null])

Sets new local name
  • Return: Previous local name
  • Access: public

Parameters:

string   $name   —  New local name

[ Top ]

name   [line 306]

string name( [string $name = null])

Sets new name of a session
  • Return: Previous name of a session
  • See: session_name()
  • Access: public

Parameters:

string   $name   —  New name of a sesion

[ Top ]

pause   [line 182]

void pause( )

Writes session data and ends session

Session data is usually stored after your script terminated without the need to call HTTP_Session::stop(), but as session data is locked to prevent concurrent writes only one script may operate on a session at any time. When using framesets together with sessions you will experience the frames loading one by one due to this locking. You can reduce the time needed to load all the frames by ending the session as soon as all changes to session variables are done.


[ Top ]

regenerateId   [line 222]

boolean regenerateId( [bool $deleteOldSessionData = false])

Calls session_regenerate_id() if available
  • Return: Obvious
  • Access: public

Parameters:

bool   $deleteOldSessionData   —  Whether to delete data of old session

[ Top ]

register   [line 488]

void register( string $name)

Register variable with the current session
  • See: session_register()
  • Access: public

Parameters:

string   $name   —  Name of a global variable

[ Top ]

registered   [line 514]

bool registered( $name)

Checks if a session variable is registered
  • Access: public

Parameters:

   $name   — 

[ Top ]

replicate   [line 253]

boolean replicate( mixed $targetTable, [mixed $id = null])

This function copies session data of specified id to specified table
  • Return: Obvious
  • Access: public

Parameters:

mixed   $targetTable   —  Table to replicate data to
mixed   $id   —  ID of the session

[ Top ]

sessionValidThru   [line 381]

integer sessionValidThru( )

Returns the time up to the session is valid
  • Return: Time when the session idles
  • Access: public

[ Top ]

set   [line 545]

mixed set( string $name, mixed $value)

Sets session variable
  • Return: Old value of a variable
  • Access: public

Parameters:

string   $name   —  Name of a variable
mixed   $value   —  Value of a variable

[ Top ]

setContainer   [line 121]

void setContainer( $container, [ $container_options = null])

Sets user-defined session storage functions

Sets the user-defined session storage functions which are used for storing and retrieving data associated with a session. This is most useful when a storage method other than those supplied by PHP sessions is preferred. i.e. Storing the session data in a local database.


Parameters:

   $container   — 
   $container_options   — 

[ Top ]

setExpire   [line 334]

void setExpire( integer $time, [bool $add = false])

Sets the maximum expire time
  • Access: public

Parameters:

integer   $time   —  Time in seconds
bool   $add   —  Add time to current expire time or not

[ Top ]

setGcMaxLifetime   [line 682]

boolean setGcMaxLifetime( [boolean $gcMaxLifetime = null])

If optional parameter is specified it determines the number of seconds after which session data will be seen as 'garbage' and cleaned up

It returns the previous value of this property

  • Return: The previous value of the property
  • Access: public

Parameters:

boolean   $gcMaxLifetime   —  If specified it will replace the previous value of this property

[ Top ]

setGcProbability   [line 704]

boolean setGcProbability( [boolean $gcProbability = null])

If optional parameter is specified it determines the probability that the gc (garbage collection) routine is started and session data is cleaned up

It returns the previous value of this property

  • Return: The previous value of the property
  • Access: public

Parameters:

boolean   $gcProbability   —  If specified it will replace the previous value of this property

[ Top ]

setIdle   [line 363]

void setIdle( integer $time, [bool $add = false])

Sets the maximum idle time

Sets the time-out period allowed between requests before the session-state provider terminates the session.

  • Access: public

Parameters:

integer   $time   —  Time in seconds
bool   $add   —  Add time to current maximum idle time or not

[ Top ]

setLocal   [line 601]

mixed setLocal( string $name, mixed $value)

Sets local variable of a script.

Two scripts can have local variables with the same names.

  • Return: Old value of a local variable
  • Access: public

Parameters:

string   $name   —  Name of a local variable
mixed   $value   —  Value of a local variable

[ Top ]

start   [line 150]

void start( [$name $name = 'SessionID'], [$id $id = null])

Initializes session data

Creates a session (or resumes the current one based on the session id being passed via a GET variable or a cookie). You can provide your own name and/or id for a session.


Parameters:

$name   $name   —  string Name of a session, default is 'SessionID'
$id   $id   —  string Id of a session which will be used only when the session is new

[ Top ]

unregister   [line 502]

void unregister( string $name)

Unregister a variable from the current session
  • See: session_unregister()
  • Access: public

Parameters:

string   $name   —  Name of a global variable

[ Top ]

updateIdle   [line 429]

void updateIdle( )

Updates the idletime
  • Access: public

[ Top ]

useCookies   [line 447]

boolean useCookies( [boolean $useCookies = null])

If optional parameter is specified it indicates whether the module will use cookies to store the session id on the client side

It returns the previous value of this property

  • Return: The previous value of the property
  • Access: public

Parameters:

boolean   $useCookies   —  If specified it will replace the previous value of this property

[ Top ]

useTransSID   [line 661]

boolean useTransSID( [boolean $useTransSID = null])

If optional parameter is specified it indicates whether the session id will automatically be appended to all links

It returns the previous value of this property

  • Return: The previous value of the property
  • Access: public

Parameters:

boolean   $useTransSID   —  If specified it will replace the previous value of this property

[ Top ]


Documentation generated on Mon, 11 Mar 2019 14:48:42 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.