.

Session Class Reference
[Lib]

Covers session handling. More...

List of all members.

Public Member Functions

  has_status ()

Static Public Member Functions

static  clear ()
static  cookies_enabled ()
  Returns TRUE, if cookies are enabled, FALSE otherwise.
static  end ()
static  get_from ($default=false)
  Static Returns the from source.
static  get_session_id ()
  Returns session id.
static  get_status ()
static  is_started ()
  Returns true, if session has been started.
static  peek ($name)
  Returns persistet value.
static  pull ($name)
  Returns persistet value and unregisters it.
static  pull_from_array ($name, $index)
  Returns persistet array member and unsets it.
static  push ($name, $value)
  Persists given value under given name.
static  push_if_empty ($name, $value)
  Persists given value under given name, if slot for name is empty.
static  push_to_array ($name, $value)
  Adds $value to array $name.
static  push_to_array_assoc ($name, $value, $key)
  Adds $value to array $name with key $key.
static  restart ($id=false)
  Regenerates session id.
static  set_from ($url)
  Static.
static  set_handler ($handler)
  Set session handler instance.
static  set_status ($status)
static  start ($id=false)
  Starts a session.
static  start_existing ()
  Starts a session, if session coookie is present;.

Public Attributes

const  FINGERPRINT = '_GYRO_FINGERPRINT_'
const  STARTED_BY_GYRO = '_GYSS__'

Detailed Description

Covers session handling.

Author:
Gerd Riesselmann

Definition at line 14 of file session.cls.php.


Member Function Documentation

static Session::clear (  )  [static]

Definition at line 122 of file session.cls.php.

00122                                        {
00123                 $_SESSION = array();
00124                 self::restart();                
00125         }
static Session::cookies_enabled (  )  [static]

Returns TRUE, if cookies are enabled, FALSE otherwise.

Returns:
Boolean

Definition at line 170 of file session.cls.php.

00170                                                  {
00171                 self::start();
00172                 if ( isset($_SESSION["cookiesenabled"]) ) {
00173                         return true;
00174                 }
00175 
00176                 // Now check for cookies
00177                 // Taken from http://www.articlecity.com/articles/web_design_and_development/article_260.shtml
00178                 if ( isset($_GET["cookietest"]) ) {
00179                         // Check if cookie was successfully set
00180                         if ( empty($_COOKIE["cookietest"]) ) {
00181                                 return false;
00182                         }
00183                         else {
00184                                 $_SESSION["cookiesenabled"] = true;
00185                                 // Delete Cookie
00186                                 setcookie("cookietest", "", time() - 3600);
00187                                 Url::current().replace_query_paramter('cookietest', '').redirect();
00188                         }
00189                 }
00190                 else {
00191                         setcookie("cookietest", "Just a test to see if cookies are enabled", 0); //time() + 60);
00192                         Url::current().replace_query_paramter('cookietest', '1').redirect();
00193                 }
00194         }
static Session::end (  )  [static]

Definition at line 127 of file session.cls.php.

00127                                      {
00128                 session_destroy();
00129         }
static Session::get_from ( default = false  )  [static]

Static Returns the from source.

Returns:
String An URL

Definition at line 312 of file session.cls.php.

00312                                                           {
00313                 $ret = self::peek('from');
00314                 if (empty($ret)) {
00315                         $ret = ($default === false) ? Config::get_url(Config::URL_DEFAULT_PAGE) : $default;
00316                 }
00317                 return $ret;
00318         }
static Session::get_session_id (  )  [static]

Returns session id.

Definition at line 161 of file session.cls.php.

00161                                                 {
00162                 return session_id();
00163         }
static Session::get_status (  )  [static]

Definition at line 326 of file session.cls.php.

00326                                             {
00327                 return self::pull("status");
00328         }
Session::has_status (  ) 

Definition at line 330 of file session.cls.php.

00330                                      {
00331                 return (self::peek('status') != false);
00332         }
static Session::is_started (  )  [static]

Returns true, if session has been started.

Definition at line 154 of file session.cls.php.

00154                                             {
00155                 return (session_id() !== '');
00156         }
static Session::peek ( name  )  [static]

Returns persistet value.

Parameters:
Name  of the value
Returns:
mixed

Definition at line 249 of file session.cls.php.

00249                                            {
00250                 self::start_existing();
00251                 if (isset($_SESSION[$name])) {
00252                         return $_SESSION[$name];
00253                 } else {
00254                         return false;
00255                 }
00256         }
static Session::pull ( name  )  [static]

Returns persistet value and unregisters it.

Parameters:
Name  of the value
Returns:
mixed

Definition at line 264 of file session.cls.php.

00264                                            {
00265                 self::start_existing();
00266                 $ret = false;
00267                 if (isset($_SESSION[$name])) {
00268                         $ret = $_SESSION[$name];
00269                         unset($_SESSION[$name]);
00270                 }
00271                 return $ret;
00272         }
static Session::pull_from_array ( name,
index  
) [static]

Returns persistet array member and unsets it.

Parameters:
string  $name Name of the array
mixed  $index Index in array
Returns:
mixed

Definition at line 281 of file session.cls.php.

00281                                                               {
00282                 self::start_existing();
00283                 $ret = false;
00284                 if (isset($_SESSION[$name][$index])) {
00285                         $ret = $_SESSION[$name][$index];
00286                         unset($_SESSION[$name][$index]);
00287                 }
00288                 return $ret;
00289         }
static Session::push ( name,
value  
) [static]

Persists given value under given name.

Parameters:
String  the name for the value
mixed  The value

Definition at line 202 of file session.cls.php.

00202                                                    {
00203                 self::start();
00204                 $_SESSION[$name] = $value;
00205         }
static Session::push_if_empty ( name,
value  
) [static]

Persists given value under given name, if slot for name is empty.

Definition at line 210 of file session.cls.php.

00210                                                             {
00211                 self::start();
00212                 if (!isset($_SESSION[$name])) {
00213                         $_SESSION[$name] = $value;
00214                 }
00215         }
static Session::push_to_array ( name,
value  
) [static]

Adds $value to array $name.

Definition at line 220 of file session.cls.php.

00220                                                             {
00221                 self::start();
00222                 $arr = self::peek($name);
00223                 if (!is_array($arr)) {
00224                         $arr = array();
00225                 }       
00226                 $arr[] = $value;
00227                 $_SESSION[$name] = $arr;
00228         }
static Session::push_to_array_assoc ( name,
value,
key  
) [static]

Adds $value to array $name with key $key.

Definition at line 233 of file session.cls.php.

00233                                                                         {
00234                 self::start();
00235                 $arr = self::peek($name);
00236                 if (!is_array($arr)) {
00237                         $arr = array();
00238                 }       
00239                 $arr[$key] = $value;
00240                 $_SESSION[$name] = $arr;
00241         }
static Session::restart ( id = false  )  [static]

Regenerates session id.

Definition at line 134 of file session.cls.php.

00134                                                     {
00135                 if (!headers_sent()) {
00136                         if ($id) {
00137                                 $backup = array();
00138                                 if (self::is_started()) {
00139                                         $backup = $_SESSION;
00140                                         self::end();
00141                                 }
00142                                 self::do_start($id);
00143                                 $_SESSION = $backup;
00144                         }
00145                         else {
00146                                 session_regenerate_id(true);
00147                         }
00148                 }
00149         }
static Session::set_from ( url  )  [static]

Static.

Sets the from source

Parameters:
String  The from URL
Returns:
void

Definition at line 298 of file session.cls.php.

00298                                               {
00299                 if ( isset($url) ) {
00300                         self::push('from', $url);
00301                 }
00302                 else    {
00303                         self::push('from', new Url(Config::get_url(Config::URL_DEFAULT_PAGE)));
00304                 }
00305         }
static Session::set_handler ( handler  )  [static]

Set session handler instance.

Parameters:
ISessionHandler  $handler

Definition at line 25 of file session.cls.php.

00025                                                      {
00026                 self::$handler = $handler;
00027         }
static Session::set_status ( status  )  [static]

Definition at line 321 of file session.cls.php.

00321                                                    {
00322                 self::push("status", $status);
00323         }
static Session::start ( id = false  )  [static]

Starts a session.

Definition at line 50 of file session.cls.php.

00050                                                   {
00051                 if (!self::is_started()) {
00052                         if (!headers_sent()) {
00053                                 self::do_start($id);
00054                         }
00055                 }
00056         }
static Session::start_existing (  )  [static]

Starts a session, if session coookie is present;.

Definition at line 61 of file session.cls.php.

00061                                                 {
00062                 if (!self::is_started()) {
00063                         $name = session_name();
00064                         if (Cookie::exists($name)) {
00065                                 self::do_start();
00066                         }
00067                 }
00068         }

Member Data Documentation

const Session::FINGERPRINT = '_GYRO_FINGERPRINT_'

Definition at line 16 of file session.cls.php.

const Session::STARTED_BY_GYRO = '_GYSS__'

Definition at line 15 of file session.cls.php.


The documentation for this class was generated from the following file: