Docs For Class CI_Session

Class CI_Session

[line 27]

Location: /Session.php

Remarks

Session Class

link

http://www.codeigniter.com/user_guide/libraries/sessions.html
 Modified as OBSession version 2.0.0 by Oscar Bajner, 19 May 2007.

author

Rick Ellis

Class Variable Summary

  • $CI =

  • $encryption =  FALSE

  • $flash_key =  'flash'

  • $gc_probability =  10

  • $now =

  • $session_cookie =  'ci_session'

  • $session_cookie_sent =  FALSE

  • $session_data = array()

  • $session_data_cookie =  'ci_session_data'

  • $session_db =

  • $session_http_only =  FALSE

  • $session_length =  0

  • $session_secure =  FALSE

  • $session_start =  0

  • $session_storage =  'cookie'

  • $session_table =  FALSE

  • $session_timeout =  0

  • $userdata = array()

Class Constant Summary

Inherited Class Constant Summary

Inherited Class Variable Summary

Method Summary

Inherited Method Summary

Method Detail

    CI_Session::CI_Session

CI_Session(
 );

    Remarks

    Session Constructor

    The constructor runs the session routines automatically whenever the class is instantiated.

    [ Top ]

    CI_Session::all_userdata

all_userdata(
string
0 );

    Parameters

    0

    Remarks

    Fetch all userdata from the session array

    access

    public

    [ Top ]

    CI_Session::flashdata

flashdata(

$key );

    Parameters

    $key

    Remarks

    Returns "flash" data for the given key.

    [ Top ]

    CI_Session::id

id(
string
0 );

    Parameters

    0

    Remarks

    Return the Session ID string

    This is a convenience function (saves typing).

    access

    public

    [ Top ]

    CI_Session::keep_flashdata

keep_flashdata(

$key );

    Parameters

    $key

    Remarks

    Keeps existing "flash" data available to next request.

    [ Top ]

    CI_Session::regenerate_id

regenerate_id(
 );

    Remarks

    Generate a new session_id, saving the old userdata and session_data

    access

    public

    [ Top ]

    CI_Session::ro_userdata

ro_userdata(
string
$item );

    Parameters

    $item

    Remarks

    Read Once Alias for userdata().

    Tail Call : Calls userdata() with the read_once parameter = TRUE

    access

    public

    [ Top ]

    CI_Session::sess_check_cookie_data

sess_check_cookie_data(

$session_data );

    Parameters

    $session_data

    Remarks

    Check the session data cookie exists and contains valid data

    access

    public

    [ Top ]

    CI_Session::sess_check_db_data

sess_check_db_data(

$session_id );

    Parameters

    $session_id

    Remarks

    Check the Database session exists and contains valid data

    access

    public

    [ Top ]

    CI_Session::sess_create

sess_create(
 );

    Remarks

    Create a new session

    access

    public

    [ Top ]

    CI_Session::sess_destroy

sess_destroy(
 );

    Remarks

    Destroy the current session

    access

    public

    [ Top ]

    CI_Session::sess_gc

sess_gc(
 );

    Remarks

    Garbage collection

    This deletes expired session rows from database if the probability percentage is met  The probability percentage is now configurable. 100 always, 0 never, 10 default

    access

    public

    [ Top ]

    CI_Session::sess_read

sess_read(
 );

    Remarks

    Fetch the current session data if it exists  Session data now consists of two parts.

    "session_data": An array, always written to the cookie. Items are prefixed with "session_". Session control info.  These are: session_id, session_start, session_last_activity, session_ip_address, session_user_agent.  "userdata": User data written to the session. Maintains backward compatibility with CI_Session class usage.  User data is stored either in the cookie or other storage medium, depending on config setting.

    access

    public

    [ Top ]

    CI_Session::sess_run

sess_run(
 );

    Remarks

    Run the session routines

    access

    public

    [ Top ]

    CI_Session::sess_send_session_cookie

sess_send_session_cookie(
[
$force = FALSE] );

    Parameters

    $force

    Remarks

    Write the session cookie

    access

    public

    [ Top ]

    CI_Session::sess_update

sess_update(
 );

    Remarks

    Update an existing session

    access

    public

    [ Top ]

    CI_Session::sess_write

sess_write(
 );

    Remarks

    Generic session Write function, writes session data to storage.

    access

    public

    [ Top ]

    CI_Session::sess_write_cookie_data

sess_write_cookie_data(
 );

    Remarks

    Write the session data cookie, if storage is 'cookie'

    access

    public

    [ Top ]

    CI_Session::sess_write_db_data

sess_write_db_data(
 );

    Remarks

    Write the session data to the DataBase

    access

    public

    [ Top ]

    CI_Session::set_flashdata

set_flashdata(
[
$newdata = array()], [
$newval = ''] );

    Parameters

    $newdata

    $newval

    Remarks

    Sets "flash" data which will be available only in next request (then it will  be deleted from session). You can use it to implement "Save succeeded" messages.

    OB - amended to mimic set_userdata(), accepts array or string as parameter

    [ Top ]

    CI_Session::set_userdata

set_userdata(
[mixed
$newdata = array()], [string
$newval = ''] );

    Parameters

    $newdata

    $newval

    Remarks

    Add or change data in the "userdata" array

    access

    public

    [ Top ]

    CI_Session::strip_slashes

strip_slashes(
mixed
$vals );

    Parameters

    $vals

    Remarks

    Strip slashes

    access

    public

    [ Top ]

    CI_Session::unset_userdata

unset_userdata(
[
$newdata = array()] );

    Parameters

    $newdata

    Remarks

    Delete a session variable from the "userdata" array

    access

    public

    [ Top ]

    CI_Session::userdata

userdata(
string
$item, [
$read_once = FALSE] );

    Parameters

    $item

    $read_once

    Remarks

    Fetch a specific item from  the session array  To implement "read once" type items, use an optional "read_once" parameter.

    If read_once is TRUE, the session item will be deleted.
    If the item is prefixed with "session_" drop it into the session_data array.

    access

    public

    [ Top ]

    CI_Session::_flashdata_mark

_flashdata_mark(
 );

    Remarks

    PRIVATE: Internal method - marks "flash" session attributes as 'old'

    [ Top ]

    CI_Session::_flashdata_sweep

_flashdata_sweep(
 );

    Remarks

    PRIVATE: Internal method - removes "flash" session marked as 'old'

    [ Top ]

Variable Detail

  • $CI =  [line 29]
    •

  • Data type: mixed
    •

  • $encryption =  FALSE [line 31]
    •

  • Data type: mixed
    •

  • $flash_key =  'flash' [line 42]
    •

  • Data type: mixed
    •

  • $gc_probability =  10 [line 39]
    •

  • Data type: mixed
    •

  • $now =  [line 30]
    •

  • Data type: mixed
    •

  • $session_cookie =  'ci_session' [line 35]
    •

  • Data type: mixed
    •

  • $session_cookie_sent =  FALSE [line 46]
    •

  • Data type: mixed
    •

  • $session_data = array() [line 38]
    •

  • Data type: mixed
    •

  • $session_data_cookie =  'ci_session_data' [line 36]
    •

  • Data type: mixed
    •

  • $session_db =  [line 45]
    •

  • Data type: mixed
    •

  • $session_http_only =  FALSE [line 43]
    •

  • Data type: mixed
    •

  • $session_length =  0 [line 34]
    •

  • Data type: mixed
    •

  • $session_secure =  FALSE [line 44]
    •

  • Data type: mixed
    •

  • $session_start =  0 [line 41]
    •

  • Data type: mixed
    •

  • $session_storage =  'cookie' [line 32]
    •

  • Data type: mixed
    •

  • $session_table =  FALSE [line 33]
    •

  • Data type: mixed
    •

  • $session_timeout =  0 [line 40]
    •

  • Data type: mixed
    •

  • $userdata = array() [line 37]
    •

  • Data type: mixed
    •

Class Constant Detail

        Documentation generated on Sun, 20 May 2007 16:16:57 +0200 by phpDocumentor 1.3.1


Package CodeIgniter Element Index

Element index for package CodeIgniter

Index of all elements
a c e f g i k n r s u _
top
_
_flashdata_mark in file Session.php, method CI_Session::_flashdata_mark()
PRIVATE: Internal method - marks "flash" session attributes as 'old'
_flashdata_sweep in file Session.php, method CI_Session::_flashdata_sweep()
PRIVATE: Internal method - removes "flash" session marked as 'old'
top
a
all_userdata in file Session.php, method CI_Session::all_userdata()
Fetch all userdata from the session array
top
c
$CI | in file Session.php, variable CI_Session::$CI
CI_Session in file Session.php, method CI_Session::CI_Session()
Session Constructor
CI_Session in file Session.php, class CI_Session
Session Class
top
e
$encryption | in file Session.php, variable CI_Session::$encryption
top
f
$flash_key | in file Session.php, variable CI_Session::$flash_key
flashdata in file Session.php, method CI_Session::flashdata()
Returns "flash" data for the given key.
top
g
$gc_probability | in file Session.php, variable CI_Session::$gc_probability
top
i
id in file Session.php, method CI_Session::id()
Return the Session ID string
top
k
keep_flashdata in file Session.php, method CI_Session::keep_flashdata()
Keeps existing "flash" data available to next request.
top
n
$now | in file Session.php, variable CI_Session::$now
top
r
regenerate_id in file Session.php, method CI_Session::regenerate_id()
Generate a new session_id, saving the old userdata and session_data
ro_userdata in file Session.php, method CI_Session::ro_userdata()
Read Once Alias for userdata().
top
s
Session.php | procedural page Session.php
$session_cookie | in file Session.php, variable CI_Session::$session_cookie
$session_cookie_sent | in file Session.php, variable CI_Session::$session_cookie_sent
$session_data | in file Session.php, variable CI_Session::$session_data
$session_data_cookie | in file Session.php, variable CI_Session::$session_data_cookie
$session_db | in file Session.php, variable CI_Session::$session_db
$session_http_only | in file Session.php, variable CI_Session::$session_http_only
$session_length | in file Session.php, variable CI_Session::$session_length
$session_secure | in file Session.php, variable CI_Session::$session_secure
$session_start | in file Session.php, variable CI_Session::$session_start
$session_storage | in file Session.php, variable CI_Session::$session_storage
$session_table | in file Session.php, variable CI_Session::$session_table
$session_timeout | in file Session.php, variable CI_Session::$session_timeout
sess_check_cookie_data in file Session.php, method CI_Session::sess_check_cookie_data()
Check the session data cookie exists and contains valid data
sess_check_db_data in file Session.php, method CI_Session::sess_check_db_data()
Check the Database session exists and contains valid data
sess_create in file Session.php, method CI_Session::sess_create()
Create a new session
sess_destroy in file Session.php, method CI_Session::sess_destroy()
Destroy the current session
sess_gc in file Session.php, method CI_Session::sess_gc()
Garbage collection
sess_read in file Session.php, method CI_Session::sess_read()
Fetch the current session data if it exists Session data now consists of two parts.
sess_run in file Session.php, method CI_Session::sess_run()
Run the session routines
sess_send_session_cookie in file Session.php, method CI_Session::sess_send_session_cookie()
Write the session cookie
sess_update in file Session.php, method CI_Session::sess_update()
Update an existing session
sess_write in file Session.php, method CI_Session::sess_write()
Generic session Write function, writes session data to storage.
sess_write_cookie_data in file Session.php, method CI_Session::sess_write_cookie_data()
Write the session data cookie, if storage is 'cookie'
sess_write_db_data in file Session.php, method CI_Session::sess_write_db_data()
Write the session data to the DataBase
set_flashdata in file Session.php, method CI_Session::set_flashdata()
Sets "flash" data which will be available only in next request (then it will be deleted from session). You can use it to implement "Save succeeded" messages.
set_userdata in file Session.php, method CI_Session::set_userdata()
Add or change data in the "userdata" array
strip_slashes in file Session.php, method CI_Session::strip_slashes()
Strip slashes
top
u
$userdata | in file Session.php, variable CI_Session::$userdata
unset_userdata in file Session.php, method CI_Session::unset_userdata()
Delete a session variable from the "userdata" array
userdata in file Session.php, method CI_Session::userdata()
Fetch a specific item from the session array To implement "read once" type items, use an optional "read_once" parameter.


Class Trees for Package CodeIgniter

Documentation generated on Sun, 20 May 2007 16:16:09 +0200 by phpDocumentor 1.3.1


Docs for page Session.php

File: /Session.php

Remarks

Code Igniter

An open source application development framework for PHP 4.3.2 or newer

since

Version 1.0

filesource

Source Code for this file

link

http://www.codeigniter.com

license

http://www.codeignitor.com/user_guide/license.html

copyright

Copyright (c) 2006, pMachine, Inc.

author

Rick Ellis

Classes in this file:
CI_Session
Session Class

Include Statements Summary

Global Variable Summary

Constant Summary

Function Summary

Include Statements Detail

Global Variable Detail

Constant Detail

Function Detail

Documentation generated on Sun, 20 May 2007 16:16:10 +0200 by phpDocumentor 1.3.1


File Source for Session.php

Source for file Session.php

Documentation is available at Session.php

  • <?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
    •

  • /**
    •

  •  * Code Igniter
    •

  •  *
    •

  •  * An open source application development framework for PHP 4.3.2 or newer
    •

  •  *
    •

  •  * @package        CodeIgniter
    •

  •  * @author        Rick Ellis
    •

  •  * @copyright    Copyright (c) 2006, pMachine, Inc.
    •

  •  * @license        http://www.codeignitor.com/user_guide/license.html
    •

  •  * @link        http://www.codeigniter.com
    •

  •  * @since        Version 1.0
    •

  •  * @filesource
    •

  •  */
    •

  • // ------------------------------------------------------------------------
    •

  • /**
    •

  •  * Session Class
    •

  •  *
    •

  •  * @package        CodeIgniter
    •

  •  * @subpackage    Libraries
    •

  •  * @category    Sessions
    •

  •  * @author        Rick Ellis
    •

  •  * @link        http://www.codeigniter.com/user_guide/libraries/sessions.html
    •

  •  *  Modified as OBSession version 2.0.0 by Oscar Bajner, 19 May 2007.
    •

  •  */
    •

  • // ------------------------------------------------------------------------
    •

  • class CI_Session {
    •

  •
    •

  •     var $CI;
    •

  •     var $now;
    •

  •     var $encryption             = FALSE;
    •

  •     var $session_storage     = 'cookie';
    •

  •     var $session_table         = FALSE;
    •

  •     var $session_length         = 0;
    •

  •     var $session_cookie         = 'ci_session';
    •

  •     var $session_data_cookie = 'ci_session_data';
    •

  •     var $userdata             = array();
    •

  •     var $session_data        = array();
    •

  •     var $gc_probability         = 10;
    •

  •     var $session_timeout     = 0;
    •

  •     var $session_start       = 0;
    •

  •     var $flash_key           = 'flash';
    •

  •     var $session_http_only   = FALSE;
    •

  •     var $session_secure      = FALSE;
    •

  •     var $session_db;
    •

  •     var $session_cookie_sent = FALSE;
    •

  •
    •

  • // ------------------------------------------------------------------------
    •

  •
    •

  •     /**
    •

  •      * Session Constructor
    •

  •      *
    •

  •      * The constructor runs the session routines automatically whenever the class is instantiated.
    •

  •      *
    •

  •      */
    •

  •     function CI_Session()
    •

  •     {
    •

  •         $this->CI =& get_instance();
    •

  •         define('OBSESSION_VERSION', '2.0.0');
    •

  •         log_message('debug', "Session Class Initialized : OBSession " . OBSESSION_VERSION);
    •

  •         $this->sess_run();
    •

  •     }
    •

  •     // --------------------------------------------------------------------
    •

  •
    •

  •     /**
    •

  •      * Run the session routines
    •

  •      *
    •

  •      * @access    public
    •

  •      * @return    void
    •

  •      */
    •

  •     function sess_run()
    •

  •     {
    •

  •         /*
    •

  •          *  Set the "now" time
    •

  •          *
    •

  •          * It can either set to GMT or time(). The pref is set in the config file.
    •

  •          * If the developer is doing any sort of time localization they might want to set the session time to GMT so
    •

  •          * they can offset the "last_activity" and "last_visit" times based on each user's locale.
    •

  •          *
    •

  •          */
    •

  •         if (strtolower($this->CI->config->item('time_reference')) == 'gmt')
    •

  •         {
    •

  •             $now = time();
    •

  •             $this->now = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now));
    •

  •
    •

  •             if (strlen($this->now) < 10)
    •

  •             {
    •

  •                 $this->now = time();
    •

  •                 log_message('error', 'The session class could not set a proper GMT timestamp so the local time() value was used.');
    •

  •             }
    •

  •         }
    •

  •         else
    •

  •         {
    •

  •             $this->now = time();
    •

  •         }
    •

  •         /*
    •

  •          *  Set the session length
    •

  •          *
    •

  •          * If the session expiration is set to zero in the config file we set the cookie expiration to 0. (FALSE)
    •

  •          * That will provide a non-persistent session which ends when the browser closes.
    •

  •          * This is effectively done by setting the session length to 12 hours. (ie if the browser session lasts
    •

  •          * longer than 12 hours the session will be terminated.
    •

  •          *
    •

  •          * NOTE: The key to the session class is the "session_last_activity". As this is updated it effectively
    •

  •          * advances the actual expiry time of the session. A new "timeout" setting allows the developer to set a
    •

  •          * fixed duration for the session lifetime.
    •

  •          */
    •

  •         $expiration = $this->CI->config->item('sess_expiration');
    •

  •
    •

  •         if (! is_numeric($expiration))
    •

  •         {
    •

  •             show_error('The session expiration configuration is invalid.');
    •

  •         }
    •

  •         $this->session_length = ($expiration > 0) ? $expiration : (60*60*12);
    •

  •
    •

  •         /*
    •

  •          *  Set the session timeout
    •

  •          *
    •

  •          * A timeout setting is provided in the config file.
    •

  •          * This allows the session to be "timed out" based on a fixed elapse of time. The session may be given a fixed
    •

  •          * duration or "time-to-live" after which it will be regenerated (with a new session id) or optionally, destroyed.
    •

  •          *
    •

  •          * To prevent any timeout, we use a config setting of 0. Effectively this means two years.
    •

  •          */
    •

  •         $timeout = $this->CI->config->item('sess_timeout');
    •

  •
    •

  •         if (! is_numeric($timeout))
    •

  •         {
    •

  •             show_error('The session timeout configuration is invalid.');
    •

  •         }
    •

  •         $this->session_timeout = ($timeout > 0) ? $timeout : (60*60*24*365*2);
    •

  •
    •

  •         // Do we need encryption?
    •

  •         $this->encryption = $this->CI->config->item('sess_encrypt_cookie');
    •

  •
    •

  •         if ($this->encryption === TRUE)
    •

  •         {
    •

  •             $this->CI->load->library('encrypt');
    •

  •         }
    •

  •
    •

  •         // Set a secure cookie?
    •

  •         if ($this->CI->config->item('sess_secure') === TRUE )
    •

  •         {
    •

  •             $this->session_secure = TRUE;
    •

  •         }
    •

  •         // Should we set the Httponly parameter?
    •

  •         // This option is only for PHP > 5.2, and only some browsers honour it. (IE 6SP1 and 7)
    •

  •         if ($this->CI->config->item('sess_http_only') === TRUE)
    •

  •         {
    •

  •             $this->session_http_only = TRUE;
    •

  •         }
    •

  •
    •

  •         // Set the session cookie name
    •

  •         if ($this->CI->config->item('sess_cookie_name') != FALSE)
    •

  •         {
    •

  •             $this->session_cookie = $this->CI->config->item('cookie_prefix').$this->CI->config->item('sess_cookie_name');
    •

  •         }
    •

  •
    •

  •         // Set the session data cookie name, if we are using cookie storage
    •

  •         if ($this->CI->config->item('sess_data_cookie_name') != FALSE)
    •

  •         {
    •

  •             $this->session_data_cookie = $this->CI->config->item('cookie_prefix').$this->CI->config->item('sess_data_cookie_name');
    •

  •         }
    •

  •
    •

  •         // Set the session storage medium, config default is cookie
    •

  •         if ($this->CI->config->item('sess_storage') != FALSE)
    •

  •         {
    •

  •             $this->session_storage = $this->CI->config->item('sess_storage');
    •

  •         }
    •

  •
    •

  •         // If storage is 'database', prepare to use the DB.
    •

  •         if ($this->session_storage == 'database' AND $this->CI->config->item('sess_table_name') != '')
    •

  •         {
    •

  •             $this->session_table = $this->CI->config->item('sess_table_name');
    •

  •             $this->session_db = $this->CI->load->database($this->CI->config->item('sess_database'), TRUE);
    •

  •         }
    •

  •         /*
    •

  •          *  Fetch the current session
    •

  •          *
    •

  •          * If a session doesn't exist we'll create a new one.  If it does, we'll update it.
    •

  •          *
    •

  •          */
    •

  •         if ( ! $this->sess_read())
    •

  •         {
    •

  •             $this->sess_create();
    •

  •         }
    •

  •         else
    •

  •         {
    •

  •             // The session is only updated periodically, (based on the config setting) to ease system load.
    •

  •             $interval = $this->CI->config->item('sess_update_interval');
    •

  •             if (! is_numeric($interval))
    •

  •             {
    •

  •                 $interval = 300;
    •

  •             }
    •

  •             if (($this->session_data['session_last_activity'] + $interval) < $this->now)
    •

  •             {
    •

  •                 $this->sess_update();
    •

  •             }
    •

  •         }
    •

  •
    •

  •         // Delete expired sessions if necessary
    •

  •         if ($this->session_storage == 'database')
    •

  •         {
    •

  •             $this->sess_gc();
    •

  •         }
    •

  •         // Delete old flashdata (from last request)
    •

  •             $this->_flashdata_sweep();
    •

  •
    •

  •         // Mark all new flashdata as old (data will be deleted before next request)
    •

  •             $this->_flashdata_mark();
    •

  •     }
    •

  •     // END sess_run()
    •

  •     // --------------------------------------------------------------------
    •

  •
    •

  •     /**
    •

  •      * Fetch the current session data if it exists
    •

  •      * Session data now consists of two parts.
    •

  •      * "session_data": An array, always written to the cookie. Items are prefixed with "session_". Session control info.
    •

  •      * These are: session_id, session_start, session_last_activity, session_ip_address, session_user_agent.
    •

  •      * "userdata": User data written to the session. Maintains backward compatibility with CI_Session class usage.
    •

  •      * User data is stored either in the cookie or other storage medium, depending on config setting.
    •

  •      * @access    public
    •

  •      * @return    void
    •

  •      */
    •

  •     function sess_read()
    •

  •     {
    •

  •         // Fetch the session cookie (only contains this session ID)
    •

  •         $session_id = $this->CI->input->cookie($this->session_cookie);
    •

  •
    •

  •         if ($session_id === FALSE)
    •

  •         {
    •

  •             log_message('debug', 'A session cookie was not found.');
    •

  •             return FALSE;
    •

  •         }
    •

  •
    •

  •         // Get the session data from the session data cookie.
    •

  •         if ($this->session_storage == 'cookie')
    •

  •         {
    •

  •             $session_data = $this->CI->input->cookie($this->session_data_cookie);
    •

  •             if ($session_data === FALSE)
    •

  •             {
    •

  •                 log_message('debug', 'A session data cookie was not found.');
    •

  •                 return FALSE;
    •

  •             }
    •

  •             // Decrypt and unserialize the session data
    •

  •             if ($this->encryption === TRUE)
    •

  •             {
    •

  •                 $session_data = $this->CI->encrypt->decode($session_data);
    •

  •             }
    •

  •
    •

  •             $session_data = @unserialize($this->strip_slashes($session_data));
    •

  •
    •

  •             if (! $this->sess_check_cookie_data($session_data))
    •

  •             {
    •

  •                 return FALSE;
    •

  •             }
    •

  •         }
    •

  •         // Get the session data from the Database
    •

  •         if ($this->session_storage == 'database')
    •

  •         {
    •

  •             $session_data = $this->sess_check_db_data($session_id);
    •

  •             if ($session_data === FALSE )
    •

  •             {
    •

  •                 log_message('debug', 'A session was not found in the database.');
    •

  •                 return FALSE;
    •

  •             }
    •

  •         }
    •

  •         // Session looks good
    •

  •         // Now we process the "session data" array, splitting session control data and user data into seperate entities.
    •

  •         foreach ($session_data as $key => $val)
    •

  •         {
    •

  •             if (substr($key, 0, 8) == 'session_')
    •

  •             {
    •

  •                 $this->session_data[$key] = $val;
    •

  •             }
    •

  •             else
    •

  •             {
    •

  •                 $this->userdata[$key] = $val;
    •

  •             }
    •

  •         }
    •

  •
    •

  •         // Session is valid!
    •

  •         unset($session_id);
    •

  •         unset($session_data);
    •

  •
    •

  •         return TRUE;
    •

  •     }
    •

  •     // --------------------------------------------------------------------
    •

  •
    •

  •     /**
    •

  •      * Check the Database session exists and contains valid data
    •

  •      *
    •

  •      *
    •

  •      * @access    public
    •

  •      * @return    mixed
    •

  •      */
    •

  •     function sess_check_db_data($session_id)
    •

  •     {
    •

  •         // Does the session exist?
    •

  •         $this->session_db->where('session_id', $session_id);
    •

  •         // Does the IP match?
    •

  •         if ($this->CI->config->item('sess_match_ip') === TRUE)
    •

  •         {
    •

  •             $this->session_db->where('session_ip_address', $this->_ip_address());
    •

  •         }
    •

  •         // Does the user agent match?
    •

  •         if ($this->CI->config->item('sess_match_useragent') === TRUE)
    •

  •         {
    •

  •             $this->session_db->where('session_user_agent', substr($this->CI->input->user_agent(), 0, 50));
    •

  •         }
    •

  •
    •

  •         $query = $this->session_db->get($this->session_table);
    •

  •         // No session found, so destroy this session, a new one will be started
    •

  •         if ($query->num_rows() == 0)
    •

  •         {
    •

  •             $this->sess_destroy();
    •

  •             return FALSE;
    •

  •         }
    •

  •         // Is this session current?
    •

  •         $row = $query->row();
    •

  •         if (($row->session_last_activity + $this->session_length) < $this->now)
    •

  •         {
    •

  •             $this->session_db->where('session_id', $session_id);
    •

  •             $this->session_db->delete($this->session_table);
    •

  •             $this->sess_destroy();
    •

  •             return FALSE;
    •

  •         }
    •

  •         // Is the session Timed Out?
    •

  •         $sess_destroy = $this->CI->config->item('sess_destroy_on_timeout');
    •

  •         if (($row->session_start + $this->session_timeout) < $this->now)
    •

  •         {
    •

  •             // If the config setting is FALSE, we regenerate the session ID on next update.
    •

  •             if ($sess_destroy === TRUE)
    •

  •             {
    •

  •                 $this->sess_destroy();
    •

  •                 return FALSE;
    •

  •             }
    •

  •         }
    •

  •         //  We have a valid session, return the session data array.
    •

  •         $session_data = @unserialize($row->session_data);
    •

  •         if ( ! is_array($session_data))
    •

  •         {
    •

  •             $session_data = array();
    •

  •         }
    •

  •         $session_data['session_id'] = $session_id;
    •

  •         $session_data['session_start'] = $row->session_start;
    •

  •         $session_data['session_last_activity'] = $row->session_last_activity;
    •

  •         $session_data['session_ip_address'] = $row->session_ip_address;
    •

  •         $session_data['session_user_agent'] = $row->session_user_agent;
    •

  •
    •

  •         return $session_data;
    •

  •     }
    •

  •     // --------------------------------------------------------------------
    •

  •
    •

  •     /**
    •

  •      * Check the session data cookie exists and contains valid data
    •

  •      *
    •

  •      *
    •

  •      * @access    public
    •

  •      * @return    boolean
    •

  •      */
    •

  •     function sess_check_cookie_data($session_data)
    •

  •     {
    •

  •         // Basic reality checks.
    •

  •         if ( ! is_array($session_data) )
    •

  •         {
    •

  •             log_message('error', 'The session data cookie did not contain a valid array. This could be a possible hacking attempt.');
    •

  •             return FALSE;
    •

  •         }
    •

  •
    •

  •         if ( ! isset($session_data['session_last_activity']) )
    •

  •         {
    •

  •             log_message('error', 'The session_last_activity is not set. This could be a possible hacking attempt.');
    •

  •             return FALSE;
    •

  •         }
    •

  •
    •

  •         // Is the session current?
    •

  •         if (($session_data['session_last_activity'] + $this->session_length) < $this->now)
    •

  •         {
    •

  •             $this->sess_destroy();
    •

  •             return FALSE;
    •

  •         }
    •

  •
    •

  •         // Does the IP Match?
    •

  •         if ($this->CI->config->item('sess_match_ip') === TRUE AND $session_data['session_ip_address'] != $this->_ip_address())
    •

  •         {
    •

  •             $this->sess_destroy();
    •

  •             return FALSE;
    •

  •         }
    •

  •
    •

  •         // Does the User Agent Match?
    •

  •         if ($this->CI->config->item('sess_match_useragent') === TRUE AND $session_data['session_user_agent'] != substr($this->CI->input->user_agent(), 0, 50))
    •

  •         {
    •

  •             $this->sess_destroy();
    •

  •             return FALSE;
    •

  •         }
    •

  •
    •

  •         // Is the session Timed Out?
    •

  •         $sess_destroy = $this->CI->config->item('sess_destroy_on_timeout');
    •

  •         if (($session_data['session_start'] + $this->session_timeout) < $this->now)
    •

  •         {
    •

  •             // If the config setting is FALSE, we regenerate the session ID on next update.
    •

  •             if ($sess_destroy === TRUE)
    •

  •             {
    •

  •                 $this->sess_destroy();
    •

  •                 return FALSE;
    •

  •             }
    •

  •         }
    •

  •         return TRUE;
    •

  •     }
    •

  •     // --------------------------------------------------------------------
    •

  •
    •

  •     /**
    •

  •      * Generic session Write function, writes session data to storage.
    •

  •      *
    •

  •      * @access    public
    •

  •      * @return    void
    •

  •      */
    •

  •     function sess_write()
    •

  •     {
    •

  •         if ($this->session_storage == 'cookie')
    •

  •         {
    •

  •             $this->sess_write_cookie_data();
    •

  •             return;
    •

  •         }
    •

  •         if ($this->session_storage == 'database')
    •

  •         {
    •

  •             $this->sess_write_db_data();
    •

  •             return;
    •

  •         }
    •

  •     }
    •

  •     // --------------------------------------------------------------------
    •

  •
    •

  •     /**
    •

  •      * Write the session cookie
    •

  •      *
    •

  •      *
    •

  •      * @access    public
    •

  •      * @return    void
    •

  •      */
    •

  •     function sess_send_session_cookie($force = FALSE)
    •

  •     {
    •

  •         if ( !$force && $this->session_cookie_sent ) {return;}
    •

  •         log_message('debug','Sending session cookie');
    •

  •
    •

  •         $cookie_data = $this->session_data['session_id'];
    •

  •
    •

  •         if ($this->encryption === TRUE)
    •

  •         {
    •

  •             $cookie_data = $this->CI->encrypt->encode($cookie_data);
    •

  •         }
    •

  •
    •

  •         $cookie_expiry = $this->CI->config->item('sess_expiration');
    •

  •         $cookie_expiry = ($cookie_expiry > 0) ? $this->session_length + time() : $cookie_expiry = 0;
    •

  •         // Check if we must set the session cookie as HttpOnly
    •

  •         if (! $this->session_http_only)
    •

  •         {
    •

  •             // This for any version of PHP < 5.2.0
    •

  •             setcookie($this->session_cookie, $cookie_data, $cookie_expiry, $this->CI->config->item('cookie_path'), $this->CI->config->item('cookie_domain'), $this->session_secure);
    •

  •         }
    •

  •         else
    •

  •         {
    •

  •             // This only for PHP >= 5.2
    •

  •             setcookie($this->session_cookie, $cookie_data, $cookie_expiry, $this->CI->config->item('cookie_path'), $this->CI->config->item('cookie_domain'), $this->session_secure, $this->session_http_only);
    •

  •         }
    •

  •
    •

  •         $this->session_cookie_sent = TRUE;
    •

  •     }
    •

  •     // --------------------------------------------------------------------
    •

  •
    •

  •     /**
    •

  •      * Write the session data cookie, if storage is 'cookie'
    •

  •      *
    •

  •      * @access    public
    •

  •      * @return    void
    •

  •      */
    •

  •     function sess_write_cookie_data()
    •

  •     {
    •

  •         $cookie_data = array();
    •

  •         $cookie_data = $this->session_data;
    •

  •
    •

  •         foreach ($this->userdata as $key => $val)
    •

  •         {
    •

  •             $cookie_data[$key] = $val;
    •

  •         }
    •

  •
    •

  •         $cookie_data = serialize($cookie_data);
    •

  •
    •

  •         if ($this->encryption === TRUE)
    •

  •         {
    •

  •             $cookie_data = $this->CI->encrypt->encode($cookie_data);
    •

  •         }
    •

  •
    •

  •         $cookie_expiry = $this->CI->config->item('sess_expiration');
    •

  •         $cookie_expiry = ($cookie_expiry > 0) ? $this->session_length + time() : $cookie_expiry = 0;
    •

  •
    •

  •         // Check if we must set the cookie as HttpOnly
    •

  •         if (! $this->session_http_only)
    •

  •         {
    •

  •             // This for any version of PHP < 5.2.0
    •

  •             setcookie($this->session_data_cookie, $cookie_data, $cookie_expiry, $this->CI->config->item('cookie_path'), $this->CI->config->item('cookie_domain'), $this->session_secure);
    •

  •         }
    •

  •         else
    •

  •         {
    •

  •             // This only for PHP >= 5.2
    •

  •             setcookie($this->session_data_cookie, $cookie_data, $cookie_expiry, $this->CI->config->item('cookie_path'), $this->CI->config->item('cookie_domain'), $this->session_secure, $this->session_http_only);
    •

  •         }
    •

  •         log_message('info','Session data cookie updated.');
    •

  •     }
    •

  •     // --------------------------------------------------------------------
    •

  •
    •

  •     /**
    •

  •      * Write the session data to the DataBase
    •

  •      *
    •

  •      *
    •

  •      * @access    public
    •

  •      * @return    void
    •

  •      */
    •

  •     function sess_write_db_data()
    •

  •     {
    •

  •         $db_user_data = $this->userdata;
    •

  •         $query_array = array('session_start'            => $this->session_data['session_start'],
    •

  •                             'session_last_activity'     => $this->session_data['session_last_activity'],
    •

  •                             'session_ip_address'        => $this->session_data['session_ip_address'],
    •

  •                             'session_user_agent'        => $this->session_data['session_user_agent']
    •

  •                             );
    •

  •
    •

  •         $query_array['session_data'] = serialize($db_user_data);
    •

  •         $this->session_db->query($this->session_db->update_string($this->session_table, $query_array, array('session_id' => $this->session_data['session_id'])));
    •

  •     }
    •

  •     // --------------------------------------------------------------------
    •

  •
    •

  •     /**
    •

  •      * Create a new session
    •

  •      *
    •

  •      * @access    public
    •

  •      * @return    void
    •

  •      */
    •

  •     function sess_create()
    •

  •     {
    •

  •         $sessid = '';
    •

  •         while (strlen($sessid) < 32)
    •

  •         {
    •

  •             $sessid .= mt_rand(0, mt_getrandmax());
    •

  •         }
    •

  •
    •

  •         $this->session_data = array(
    •

  •                             'session_id'             => md5(uniqid($sessid, TRUE)),
    •

  •                             'session_start'         => $this->now,
    •

  •                             'session_last_activity'    => $this->now,
    •

  •                             'session_ip_address'     => $this->_ip_address(),
    •

  •                             'session_user_agent'     => substr($this->CI->input->user_agent(), 0, 50)
    •

  •                             );
    •

  •
    •

  •         $this->userdata = array();
    •

  •
    •

  •         // Create the session in the DB if session storage is 'database'
    •

  •         if ($this->session_storage == 'database')
    •

  •         {
    •

  •             $this->session_db->query($this->session_db->insert_string($this->session_table, $this->session_data));
    •

  •             $this->sess_send_session_cookie();
    •

  •         }
    •

  •         // Create the session in the session data cookie if session storage is 'cookie'
    •

  •         if ($this->session_storage == 'cookie')
    •

  •         {
    •

  •             $this->sess_send_session_cookie();
    •

  •             $this->sess_write_cookie_data();
    •

  •         }
    •

  •
    •

  •         log_message('debug','New session started.');
    •

  •     }
    •

  •     // --------------------------------------------------------------------
    •

  •
    •

  •     /**
    •

  •      * Update an existing session
    •

  •      *
    •

  •      * @access    public
    •

  •      * @return    void
    •

  •      */
    •

  •     function sess_update()
    •

  •     {
    •

  •         // Is the session Timed Out? If so we regenerate the session, new id,  keep the old data.
    •

  •         $sess_destroy = $this->CI->config->item('sess_destroy_on_timeout');
    •

  •         if (($this->session_data['session_start'] + $this->session_timeout) < $this->now)
    •

  •         {
    •

  •             if ($sess_destroy === FALSE)
    •

  •             {
    •

  •                 $this->regenerate_id();
    •

  •                 return;
    •

  •             }
    •

  •         }
    •

  •         // This little piggy drives the whole session.
    •

  •         $this->session_data['session_last_activity'] = $this->now;
    •

  •
    •

  •         if ($this->session_storage == 'database')
    •

  •         {
    •

  •             $this->session_db->query($this->session_db->update_string($this->session_table, array('session_last_activity' => $this->now), array('session_id' => $this->session_data['session_id'])));
    •

  •         }
    •

  •
    •

  •         if ($this->session_storage == 'cookie')
    •

  •         {
    •

  •             $this->sess_write_cookie_data();
    •

  •         }
    •

  •     }
    •

  •     // --------------------------------------------------------------------
    •

  •
    •

  •     /**
    •

  •      * Destroy the current session
    •

  •      *
    •

  •      * @access    public
    •

  •      * @return    void
    •

  •      */
    •

  •     function sess_destroy()
    •

  •     {
    •

  •         // If we are using a database, delete the session row now.
    •

  •         if ($this->session_storage == 'database')
    •

  •         {
    •

  •             if ( isset( $this->session_data['session_id'] ))
    •

  •             {
    •

  •                  $this->session_db->where('session_id', $this->session_data['session_id']);
    •

  •                  $this->session_db->delete($this->session_table);
    •

  •             }
    •

  •         }
    •

  •         if ($this->session_storage == 'cookie')
    •

  •         {
    •

  •             setcookie($this->session_data_cookie, '', ($this->now - 31500000), $this->CI->config->item('cookie_path'), $this->CI->config->item('cookie_domain'), $this->CI->config->item('sess_secure'));
    •

  •         }
    •

  •         // Finally, delete the session cookie. This effectively destroys the session.
    •

  •         setcookie($this->session_cookie, '', ($this->now - 31500000), $this->CI->config->item('cookie_path'), $this->CI->config->item('cookie_domain'), $this->CI->config->item('sess_secure'));
    •

  •     }
    •

  •     // --------------------------------------------------------------------
    •

  •
    •

  •     /**
    •

  •      * Generate a new session_id, saving the old userdata and session_data
    •

  •      *
    •

  •      * @access    public
    •

  •      * @return    void
    •

  •      */
    •

  •     function regenerate_id()
    •

  •     {
    •

  •         $sessid = '';
    •

  •         while (strlen($sessid) < 32)
    •

  •         {
    •

  •             $sessid .= mt_rand(0, mt_getrandmax());
    •

  •         }
    •

  •
    •

  •         // Update the session data in the session data array.
    •

  •         $this->session_data['session_id'] = md5(uniqid($sessid, TRUE));
    •

  •         $this->session_data['session_start'] = $this->now;
    •

  •         $this->session_data['session_last_activity'] = $this->now;
    •

  •
    •

  •         // We MUST resend the session cookie with the NEW session ID.
    •

  •         $this->sess_send_session_cookie($force = TRUE);
    •

  •
    •

  •         if ($this->session_storage == 'cookie')
    •

  •         {
    •

  •             $this->sess_write_cookie_data();
    •

  •         }
    •

  •         // The session_id has changed, so insert a new row into the database.
    •

  •         if ($this->session_storage == 'database')
    •

  •         {
    •

  •             $db_sess_data = array();
    •

  •             $db_sess_data = $this->session_data;
    •

  •             $this->session_db->query($this->session_db->insert_string($this->session_table, $db_sess_data));
    •

  •             // We now have a new db session, make sure the userdata is updated
    •

  •             $this->sess_write_db_data();
    •

  •         }
    •

  •     }
    •

  •     // --------------------------------------------------------------------
    •

  •
    •

  •     /**
    •

  •      * Garbage collection
    •

  •      *
    •

  •      * This deletes expired session rows from database if the probability percentage is met
    •

  •      * The probability percentage is now configurable. 100 always, 0 never, 10 default
    •

  •      *
    •

  •      * @access    public
    •

  •      * @return    void
    •

  •      */
    •

  •     function sess_gc()
    •

  •     {
    •

  •         $gc_prob = $this->CI->config->item('sess_gc_probability');
    •

  •         if ($this->gc_probability != $gc_prob)
    •

  •         {
    •

  •             $this->gc_probability = $gc_prob;
    •

  •         }
    •

  •
    •

  •         srand(time());
    •

  •         if ((rand() % 100) < $this->gc_probability)
    •

  •         {
    •

  •             $expire = $this->now - $this->session_length;
    •

  •             $this->session_db->where("session_last_activity < {$expire}");
    •

  •             $this->session_db->delete($this->session_table);
    •

  •
    •

  •             log_message('debug', 'Session garbage collection performed.');
    •

  •         }
    •

  •     }
    •

  •     // --------------------------------------------------------------------
    •

  •
    •

  •     /**
    •

  •      * Fetch a specific item from  the session array
    •

  •      * To implement "read once" type items, use an optional "read_once" parameter.
    •

  •      * If read_once is TRUE, the session item will be deleted.
    •

  •      *
    •

  •      * If the item is prefixed with "session_" drop it into the session_data array.
    •

  •      * @access    public
    •

  •      * @param    string
    •

  •      * @return    string
    •

  •      */
    •

  •     function userdata($item, $read_once = FALSE)
    •

  •     {
    •

  •         if (substr($item, 0, 8) == 'session_') // This is a session control item
    •

  •         {
    •

  •             return ( ! isset($this->session_data[$item])) ? FALSE : $this->session_data[$item];
    •

  •         }
    •

  •
    •

  •         if ($read_once === FALSE) // This is an ordinary session variable, just return it.
    •

  •         {
    •

  •             return ( ! isset($this->userdata[$item])) ? FALSE : $this->userdata[$item];
    •

  •         }
    •

  •         else // This is a read-once variable, delete the session item and return the value
    •

  •         {
    •

  •             // Save the value to return, and unset the session variable
    •

  •             if (isset($this->userdata[$item]))
    •

  •             {
    •

  •                 $user_item = $this->userdata[$item];
    •

  •                 $this->unset_userdata($item);
    •

  •                 return $user_item;
    •

  •             }
    •

  •             else // The item does not exist, return false and do not unset it.
    •

  •             {
    •

  •                 return FALSE;
    •

  •             }
    •

  •         }
    •

  •     }
    •

  •     // --------------------------------------------------------------------
    •

  •
    •

  •     /**
    •

  •      * Read Once Alias for userdata().
    •

  •      * Tail Call : Calls userdata() with the read_once parameter = TRUE
    •

  •      *
    •

  •      * @access    public
    •

  •      * @param    string
    •

  •      * @return    string
    •

  •      */
    •

  •     function ro_userdata($item)
    •

  •     {
    •

  •         return $this->userdata($item, TRUE);
    •

  •     }
    •

  •     // --------------------------------------------------------------------
    •

  •
    •

  •     /**
    •

  •      * Fetch all userdata from the session array
    •

  •      *
    •

  •      * @access    public
    •

  •      * @param    string
    •

  •      * @return    array
    •

  •      */
    •

  •     function all_userdata()
    •

  •     {
    •

  •         return ( ! isset($this->userdata)) ? FALSE : $this->userdata;
    •

  •     }
    •

  •     // --------------------------------------------------------------------
    •

  •
    •

  •     /**
    •

  •      * Add or change data in the "userdata" array
    •

  •      *
    •

  •      * @access    public
    •

  •      * @param    mixed
    •

  •      * @param    string
    •

  •      * @return    void
    •

  •      */
    •

  •     function set_userdata($newdata = array(), $newval = '')
    •

  •     {
    •

  •         if (is_string($newdata))
    •

  •         {
    •

  •             $newdata = array($newdata => $newval);
    •

  •         }
    •

  •
    •

  •         if (count($newdata) > 0)
    •

  •         {
    •

  •             foreach ($newdata as $key => $val)
    •

  •             {
    •

  •                 $this->userdata[$key] = $val;
    •

  •             }
    •

  •         }
    •

  •
    •

  •         $this->sess_write();
    •

  •     }
    •

  •     // --------------------------------------------------------------------
    •

  •
    •

  •     /**
    •

  •      * Delete a session variable from the "userdata" array
    •

  •      *
    •

  •      * @access    public
    •

  •      * @return    void
    •

  •      */
    •

  •     function unset_userdata($newdata = array())
    •

  •     {
    •

  •         if (is_string($newdata))
    •

  •         {
    •

  •             $newdata = array($newdata => '');
    •

  •         }
    •

  •
    •

  •         if (count($newdata) > 0)
    •

  •         {
    •

  •             foreach ($newdata as $key => $val)
    •

  •             {
    •

  •                 unset($this->userdata[$key]);
    •

  •             }
    •

  •         }
    •

  •
    •

  •         $this->sess_write();
    •

  •     }
    •

  •     // --------------------------------------------------------------------
    •

  •
    •

  •     /**
    •

  •      * Return the Session ID string
    •

  •      *
    •

  •      * This is a convenience function (saves typing).
    •

  •      * @access    public
    •

  •      * @param    string
    •

  •      * @return    string
    •

  •      */
    •

  •     function id()
    •

  •     {
    •

  •         return ( ! isset($this->session_data['session_id'])) ? FALSE : $this->session_data['session_id'];
    •

  •     }
    •

  •     // --------------------------------------------------------------------
    •

  •
    •

  •     /**
    •

  •      * Strip slashes
    •

  •      *
    •

  •      * @access    public
    •

  •      * @param    mixed
    •

  •      * @return    mixed
    •

  •      */
    •

  •      function strip_slashes($vals)
    •

  •      {
    •

  •          if (is_array($vals))
    •

  •          {
    •

  •              foreach ($vals as $key=>$val)
    •

  •              {
    •

  •                  $vals[$key] = $this->strip_slashes($val);
    •

  •              }
    •

  •          }
    •

  •          else
    •

  •          {
    •

  •              $vals = stripslashes($vals);
    •

  •          }
    •

  •
    •

  •          return $vals;
    •

  •     }
    •

  •     // ------------------------------------------------------------------------
    •

  •
    •

  •     /**
    •

  •     * Sets "flash" data which will be available only in next request (then it will
    •

  •     * be deleted from session). You can use it to implement "Save succeeded" messages.
    •

  •     * OB - amended to mimic set_userdata(), accepts array or string as parameter
    •

  •     */
    •

  •     function set_flashdata($newdata = array(), $newval = '')
    •

  •     {
    •

  •         if (is_string($newdata))
    •

  •         {
    •

  •             $newdata = array($newdata => $newval);
    •

  •         }
    •

  •
    •

  •         if (count($newdata) > 0)
    •

  •         {
    •

  •             foreach ($newdata as $key => $val)
    •

  •             {
    •

  •                 $flash_key = $this->flash_key.':new:'.$key;
    •

  •                 $this->set_userdata($flash_key, $val);
    •

  •             }
    •

  •         }
    •

  •     }
    •

  •     // ------------------------------------------------------------------------
    •

  •
    •

  •     /**
    •

  •     * Keeps existing "flash" data available to next request.
    •

  •     */
    •

  •     function keep_flashdata($key)
    •

  •     {
    •

  •         $old_flash_key = $this->flash_key.':old:'.$key;
    •

  •         $value = $this->userdata($old_flash_key);
    •

  •
    •

  •         $new_flash_key = $this->flash_key.':new:'.$key;
    •

  •         $this->set_userdata($new_flash_key, $value);
    •

  •     }
    •

  •     // ------------------------------------------------------------------------
    •

  •
    •

  •     /**
    •

  •     * Returns "flash" data for the given key.
    •

  •     */
    •

  •     function flashdata($key)
    •

  •     {
    •

  •         $flash_key = $this->flash_key.':old:'.$key;
    •

  •         return $this->userdata($flash_key);
    •

  •     }
    •

  •     // ------------------------------------------------------------------------
    •

  •
    •

  •     /**
    •

  •     * PRIVATE: Internal method - marks "flash" session attributes as 'old'
    •

  •     */
    •

  •     function _flashdata_mark()
    •

  •     {
    •

  •     $userdata = $this->all_userdata();
    •

  •         foreach ($userdata as $name => $value)
    •

  •         {
    •

  •             $parts = explode(':new:', $name);
    •

  •             if (is_array($parts) && count($parts) == 2)
    •

  •             {
    •

  •                 $new_name = $this->flash_key.':old:'.$parts[1];
    •

  •                 $this->set_userdata($new_name, $value);
    •

  •                 $this->unset_userdata($name);
    •

  •             }
    •

  •         }
    •

  •     }
    •

  •     // ------------------------------------------------------------------------
    •

  •
    •

  •     /**
    •

  •     * PRIVATE: Internal method - removes "flash" session marked as 'old'
    •

  •     */
    •

  •     function _flashdata_sweep()
    •

  •     {
    •

  •     $userdata = $this->all_userdata();
    •

  •         foreach ($userdata as $name => $value)
    •

  •         {
    •

  •             $parts = explode(':old:', $name);
    •

  •             if (is_array($parts) && count($parts) == 2 && $parts[0] == $this->flash_key)
    •

  •             {
    •

  •                 $this->unset_userdata($name);
    •

  •             }
    •

  •         }
    •

  •     }
    •

  •     // ------------------------------------------------------------------------
    •

  •
    •

  •     /**
    •

  •      * Return the Session IP address
    •

  •      *
    •

  •      * Call CI Input Class, returning the IP address.
    •

  •      * If config sess_forwarded_ip is TRUE, and a valid HTTP_X_FORWARDED_FOR address exists,
    •

  •      * then return the HTTP_X_FORWARDED address, else use the original address.
    •

  •      * @access    private
    •

  •      * @param    string
    •

  •      * @return    string
    •

  •      */
    •

  •     function _ip_address()
    •

  •     {
    •

  •         $use_forwarded = $this->CI->config->item('sess_forwarded_ip');
    •

  •         $ip = $this->CI->input->ip_address();
    •

  •         if (! $use_forwarded)
    •

  •         {
    •

  •             return $ip;
    •

  •         }
    •

  •         // If CI input class returned '0.0.0.0', we're screwed anyway
    •

  •         if ($ip == '0.0.0.0')
    •

  •         {
    •

  •             return $ip;
    •

  •         }
    •

  •         // If a valid HTTP_X_FORWARDED address exists, use it, otherwise use first IP
    •

  •         // I'm duplicating things, because if CI dev changes the Input class to return
    •

  •         // the forwarded IP as some have asked, I can rip this out easily.
    •

  •         $x_ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    •

  •         // From CI input class, if multiple IP's exist, get the last one
    •

  •         if (strstr($x_ip, ','))
    •

  •         {
    •

  •             $x = explode(',', $x_ip);
    •

  •             $x_ip = end($x);
    •

  •         }
    •

  •         // Is it valid?
    •

  •         if ( ! $this->CI->input->valid_ip($x_ip))
    •

  •         {
    •

  •             return $ip; // The original address returned by CI input class
    •

  •         }
    •

  •
    •

  •         return $x_ip; // return valid HTTP_X_FORWARDED_FOR
    •

  •     }
    •

  • }
    •

  • // END Session Class
    •

  • ?>
    •
    Documentation generated on Sun, 20 May 2007 16:16:56 +0200 by phpDocumentor 1.3.1


Element Index

Index of All Elements

Indexes by package:
CodeIgniter

a c e f g i k n r s u _
top
a
all_userdata in file Session.php, method CI_Session::all_userdata()
Fetch all userdata from the session array
top
c
$CI | in file Session.php, variable CI_Session::$CI
CI_Session in file Session.php, method CI_Session::CI_Session()
Session Constructor
CI_Session in file Session.php, class CI_Session
Session Class
top
e
$encryption | in file Session.php, variable CI_Session::$encryption
top
f
$flash_key | in file Session.php, variable CI_Session::$flash_key
flashdata in file Session.php, method CI_Session::flashdata()
Returns "flash" data for the given key.
top
g
$gc_probability | in file Session.php, variable CI_Session::$gc_probability
top
i
id in file Session.php, method CI_Session::id()
Return the Session ID string
top
k
keep_flashdata in file Session.php, method CI_Session::keep_flashdata()
Keeps existing "flash" data available to next request.
top
n
$now | in file Session.php, variable CI_Session::$now
top
r
regenerate_id in file Session.php, method CI_Session::regenerate_id()
Generate a new session_id, saving the old userdata and session_data
ro_userdata in file Session.php, method CI_Session::ro_userdata()
Read Once Alias for userdata().
top
s
$session_cookie | in file Session.php, variable CI_Session::$session_cookie
$session_cookie_sent | in file Session.php, variable CI_Session::$session_cookie_sent
$session_data | in file Session.php, variable CI_Session::$session_data
$session_data_cookie | in file Session.php, variable CI_Session::$session_data_cookie
$session_db | in file Session.php, variable CI_Session::$session_db
$session_http_only | in file Session.php, variable CI_Session::$session_http_only
$session_length | in file Session.php, variable CI_Session::$session_length
$session_secure | in file Session.php, variable CI_Session::$session_secure
$session_start | in file Session.php, variable CI_Session::$session_start
$session_storage | in file Session.php, variable CI_Session::$session_storage
$session_table | in file Session.php, variable CI_Session::$session_table
$session_timeout | in file Session.php, variable CI_Session::$session_timeout
Session.php | procedural page Session.php
sess_check_cookie_data in file Session.php, method CI_Session::sess_check_cookie_data()
Check the session data cookie exists and contains valid data
sess_check_db_data in file Session.php, method CI_Session::sess_check_db_data()
Check the Database session exists and contains valid data
sess_create in file Session.php, method CI_Session::sess_create()
Create a new session
sess_destroy in file Session.php, method CI_Session::sess_destroy()
Destroy the current session
sess_gc in file Session.php, method CI_Session::sess_gc()
Garbage collection
sess_read in file Session.php, method CI_Session::sess_read()
Fetch the current session data if it exists Session data now consists of two parts.
sess_run in file Session.php, method CI_Session::sess_run()
Run the session routines
sess_send_session_cookie in file Session.php, method CI_Session::sess_send_session_cookie()
Write the session cookie
sess_update in file Session.php, method CI_Session::sess_update()
Update an existing session
sess_write in file Session.php, method CI_Session::sess_write()
Generic session Write function, writes session data to storage.
sess_write_cookie_data in file Session.php, method CI_Session::sess_write_cookie_data()
Write the session data cookie, if storage is 'cookie'
sess_write_db_data in file Session.php, method CI_Session::sess_write_db_data()
Write the session data to the DataBase
set_flashdata in file Session.php, method CI_Session::set_flashdata()
Sets "flash" data which will be available only in next request (then it will be deleted from session). You can use it to implement "Save succeeded" messages.
set_userdata in file Session.php, method CI_Session::set_userdata()
Add or change data in the "userdata" array
strip_slashes in file Session.php, method CI_Session::strip_slashes()
Strip slashes
top
u
$userdata | in file Session.php, variable CI_Session::$userdata
unset_userdata in file Session.php, method CI_Session::unset_userdata()
Delete a session variable from the "userdata" array
userdata in file Session.php, method CI_Session::userdata()
Fetch a specific item from the session array To implement "read once" type items, use an optional "read_once" parameter.
top
_
_flashdata_mark in file Session.php, method CI_Session::_flashdata_mark()
PRIVATE: Internal method - marks "flash" session attributes as 'old'
_flashdata_sweep in file Session.php, method CI_Session::_flashdata_sweep()
PRIVATE: Internal method - removes "flash" session marked as 'old'


Generated Documentation

Welcome to default!

This documentation was generated by phpDocumentor v1.3.1


phpDocumentor Parser Errors and Warnings

 Post-parsing
Documentation generated on Sun, 20 May 2007 16:17:25 +0200 by phpDocumentor 1.3.1


Documentation generated on Sun, 20 May 2007 16:16:09 +0200 by phpDocumentor 1.3.1