Category:Libraries -> Session
A session library from systemsos;
Version 2.3 - Updated 26/02/2008 Working (better even)
Welcome to RA_Session, using native PHP sessions and two great features.
-> A Remember me setting, to store the viewer’s username or email address - ready to be automatically placed on a login form for when they return.
-> Persistant Session, is the function to define if the user wants to “Keep me Logged In”, where everyone else is automatically logged out after they close their brower. This can be set on a PER USER basis, giving you the option to ask users to keep logged in for 1 hour, 2 hours, 1 week, etc. or whatever you can come up with.
I’ve tried to keep the CI’s function names in tact so it will work with all your current scripts - without having to change and modify mass amounts of code [posted below].
Functions
$this->load->library('RA_Session'); //To start a sesssion
$this->ra_session->sess_destroy; //Destory the session (or log out the user) - does not remove persistant_session state or the remember me state
//The following functions have been kept (keep using them if you want to encrypt your data
$this->ra_session->userdata
$this->ra_session->all_userdata
$this->ra_session->set_userdata
$this->ra_session->unset_userdata
SPECIAL FUNCTIONS
$this->ra_session->sess_id() //Returns the Native Session ID
/**************************************************
// Remember Me Usage
// remember_me ('my_username'); //sets remember_me value as 'my_username'
// remember_me ($username); //sets remember_me value to $username
// remember_me (); //returns remember_me value
//
// Default Action - RETURN CURRENT SETTING
//
// FALSE - Destory the Setting/Cookie
// $string - Remember this string
// NULL or '' - Return Current String for Remember Me
//
**************************************************/
/**************************************************
// Persistant Session Usage (must be entered in as seconds)
// persistant_session ('3600'); //sets this session length to 1 hour (60 * 60)
// persistant_session ($session_length); //sets this session length to $session_length
// persistant_session (); //returns this session length time
//
// Default Action - RETURN CURRENT SETTING
//
// FALSE - Destory the Setting/Cookie
// $time - Keep Session Active for $time in seconds
// NULL or '' - Return Current String for Remember Me
// TRUE - Keep Session Active indefinantly (2 years)
**************************************************/
/**************************************************
// Regenerate Session Usage (optional new session name)
// persistant_session ('0001'); //regenerates the session with an ID of 0001
// persistant_session ($new_session_id); //regenerates the session with an ID of $new_session_id
// persistant_session('NEW'); //regenerates the session with a new generated id
// persistant_session (); //regenerates the session with the same session id
//
// Default Action - regenerate the session with the same session id
//
// NULL or '' - regenerate the session with the same session id
// $string - regnereate the session with a session id = $string
// 'NEW' - regenerate the session with a newly generated id
**************************************************/
If you wish to use the Persistant Session option - you should consider having your $sess_length (at the top of this file, or set in your config.php file) to 0. Zero defaults to close this session on browser exit. Anything higher and you’ll get some unexpected results.
****ChangeLog V2.3
Joe_Archer from the community forums pointed out a problem in the code not session destroy function not working. Nailed down to an improper use of testing for NULL and ‘’ (should be === or is_null rather than to check for == NULL). Thanks Joe.
****ChangeLog V2.2
* Added flash session abilities from orginal session library
****
****Changelog V2.1
* Session expiry is renewed each time a new page is loaded (Reduces the need for a regnerate session function to be run)
* Cookie for persistant session now reflects your base session name with _persist
* Code was cleaned up (there were a few 1=1 statements)
* Productive comments Added
* Less coffee was drank - although was not completed remove. I make no warrenty against coffee stains found in this code
****
***Notes about Config
*Values listed here in the library are the default values
*but these values can be put in the applications config.php file instead of
*direct changes to the library
***
