Added Flashdata variables, session_id regeneration and configurable session update times to the Session class
diff --git a/system/application/config/config.php b/system/application/config/config.php
index f0ba241..c84a4d8 100644
--- a/system/application/config/config.php
+++ b/system/application/config/config.php
@@ -227,6 +227,7 @@
 | 'encrypt_sess_cookie' = TRUE/FALSE (boolean).  Whether to encrypt the cookie

 | 'session_expiration'  = the number of SECONDS you want the session to last.

 |  by default sessions last 7200 seconds (two hours).  Set to zero for no expiration.

+| 'time_to_update'		= how many seconds between CI refreshing Session Information

 |

 */

 $config['sess_cookie_name']		= 'ci_session';

@@ -236,6 +237,7 @@
 $config['sess_table_name']		= 'ci_sessions';

 $config['sess_match_ip']		= FALSE;

 $config['sess_match_useragent']	= TRUE;

+$config['sess_time_to_update'] 		= 300;

 

 /*

 |--------------------------------------------------------------------------

diff --git a/system/libraries/Session.php b/system/libraries/Session.php
index a0fe562..57106ea 100644
--- a/system/libraries/Session.php
+++ b/system/libraries/Session.php
@@ -35,7 +35,8 @@
 	var $sess_cookie	= 'ci_session';

 	var $userdata		= array();

 	var $gc_probability	= 5;

-

+	var $flashdata_key 	= 'flash';

+	var $time_to_update	= 300; // 5 mintues, not accessible from config settings

 

 	/**

 	 * Session Constructor

@@ -72,6 +73,12 @@
 		 * "last_visit" times based on each user's locale.

 		 *

 		 */

+

+		if (is_numeric($this->CI->config->item('sess_time_to_update')))

+		{

+			$this->time_to_update = $this->CI->config->item('sess_time_to_update');

+		}

+

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

 		{

 			$now = time();

@@ -146,7 +153,7 @@
 		else

 		{	

 			// We only update the session every five minutes

-			if (($this->userdata['last_activity'] + 300) < $this->now)

+			if (($this->userdata['last_activity'] + $this->time_to_update) < $this->now)

 			{

 				$this->sess_update();

 			}

@@ -156,7 +163,13 @@
 		if ($this->use_database === TRUE)

 		{		

 			$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();

 	}

 	

 	// --------------------------------------------------------------------

@@ -313,7 +326,7 @@
 		}

 			

 		// Write the cookie

-		$this->userdata['last_visit'] = 0;		

+		$this->userdata['last_visit'] = 0;

 		$this->sess_write();

 	}

 	

@@ -331,13 +344,25 @@
 		{

 			$this->userdata['last_visit'] = $this->userdata['last_activity'];

 		}

-	

+

+		// Save the old session id so we know which record to 

+		// update in the database if we need it

+		$old_sessid = $this->userdata['session_id'];

+		$new_sessid = '';

+		while (strlen($new_sessid) < 32)

+		{

+			$new_sessid .= mt_rand(0, mt_getrandmax());

+		}

+		$new_sessid = md5(uniqid($new_sessid, TRUE));

+		

+        // Update the session data in the session data array

+		$this->userdata['session_id'] = $new_sessid;

 		$this->userdata['last_activity'] = $this->now;

 		

 		// Update the session in the DB if needed

 		if ($this->use_database === TRUE)

 		{		

-			$this->CI->db->query($this->CI->db->update_string($this->session_table, array('last_activity' => $this->now), array('session_id' => $this->userdata['session_id'])));

+			$this->CI->db->query($this->CI->db->update_string($this->session_table, array('last_activity' => $this->now, 'session_id' => $new_sessid), array('session_id' => $old_sessid)));

 		}

 		

 		// Write the cookie

@@ -392,7 +417,7 @@
 	// --------------------------------------------------------------------

 	

 	/**

-	 * Fetch a specific item form  the session array

+	 * Fetch a specific item from the session array

 	 *

 	 * @access	public

 	 * @param	string

@@ -402,6 +427,19 @@
 	{

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

 	}

+

+	// --------------------------------------------------------------------

+	

+	/**

+	 * Fetch all session data

+	 *

+	 * @access	public

+	 * @return	mixed

+	 */	

+	function all_userdata()

+	{

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

+	}

 	

 	// --------------------------------------------------------------------

 	

@@ -427,7 +465,7 @@
 				$this->userdata[$key] = $val;

 			}

 		}

-	

+

 		$this->sess_write();

 	}

 	

@@ -436,8 +474,7 @@
 	/**

 	 * Delete a session variable from the "userdata" array

 	 *

-	 * @access	public

-	 * @param	array

+	 * @access	array

 	 * @return	void

 	 */		

 	function unset_userdata($newdata = array())

@@ -467,9 +504,9 @@
 	 * @param	mixed

 	 * @return	mixed

 	 */

-	 function strip_slashes($vals)

-	 {

-	 	if (is_array($vals))

+	function strip_slashes($vals)

+	{

+		if (is_array($vals))

 	 	{	

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

 	 		{

@@ -484,6 +521,118 @@
 	 	return $vals;

 	}

 

+	

+    // ------------------------------------------------------------------------

+

+    /**

+	 * Add or change flashdata, only available

+	 * until the next request

+	 *

+	 * @access	public

+	 * @param	mixed

+	 * @param	string

+	 * @return	void

+	 */

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

+    {

+        if (is_string($newdata))

+        {

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

+        }

+        

+        if (count($newdata) > 0)

+        {

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

+            {

+                $flashdata_key = $this->flashdata_key.':new:'.$key;

+                $this->set_userdata($flashdata_key, $val);

+            }

+        }

+    } 

+	

+    // ------------------------------------------------------------------------

+

+    /**

+     * Keeps existing flashdata available to next request.

+	 *

+	 * @access	public

+	 * @param	string

+	 * @return	void

+     */

+    function keep_flashdata($key)

+    {

+		// 'old' flashdata gets removed.  Here we mark all 

+		// flashdata as 'new' to preserve it from _flashdata_sweep()

+		// Note the function will return FALSE if the $key 

+		// provided cannot be found

+        $old_flashdata_key = $this->flashdata_key.':old:'.$key;

+        $value = $this->userdata($old_flashdata_key);

+

+        $new_flashdata_key = $this->flashdata_key.':new:'.$key;

+        $this->set_userdata($new_flashdata_key, $value);

+    }

+	

+    // ------------------------------------------------------------------------

+

+	/**

+	 * Fetch a specific flashdata item from the session array

+	 *

+	 * @access	public

+	 * @param	string

+	 * @return	string

+	 */	

+    function flashdata($key)

+    {

+        $flashdata_key = $this->flashdata_key.':old:'.$key;

+        return $this->userdata($flashdata_key);

+    }

+

+    // ------------------------------------------------------------------------

+

+    /**

+     * Identifies flashdata as 'old' for removal

+	 * when _flashdata_sweep() runs.

+	 *

+	 * @access	private

+	 * @return	void

+     */

+    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->flashdata_key.':old:'.$parts[1];

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

+                $this->unset_userdata($name);

+            }

+        }

+    }

+

+    // ------------------------------------------------------------------------

+

+    /**

+     * Removes all flashdata marked as 'old'

+	 *

+	 * @access	private

+	 * @return	void

+     */

+

+    function _flashdata_sweep()

+    {

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

+        foreach ($userdata as $key => $value)

+        {

+            if (strpos($key, ':old:'))

+            {

+                $this->unset_userdata($key);

+            }

+        }

+

+    }

+	

 }

 // END Session Class

 ?>
\ No newline at end of file
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index 26d41ed..0433e71 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -65,6 +65,7 @@
 <h2>Version 1.5.5</h2>

 <p>Release Date: -- still in development </p>

 <ul>

+	<li>Added Flashdata variables, session_id regeneration and configurable session update   times to the <a href="./libraries/Session.php">Session class</a> </li>

 	<li>Added $this->DB->save_queries variable to DB driver, enabling queries to get saved or no. Previously they were always saved.</li>

 	<li>Added <dfn>$assign_to_controller</dfn> variable in the main <kbd>index.php</kbd> file.  Anything that this variable contains will be passed automatically to a controller constructor when initialized.</li>

 	<li>Reorganized the URI and Routes classes for better clarity.</li>

diff --git a/user_guide/installation/upgrade_155.html b/user_guide/installation/upgrade_155.html
new file mode 100644
index 0000000..9a8400a
--- /dev/null
+++ b/user_guide/installation/upgrade_155.html
@@ -0,0 +1,106 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

+<html>

+<head>

+

+<title>CodeIgniter User Guide : Upgrading from 1.5.3 to 1.5.4</title>

+

+<style type='text/css' media='all'>@import url('../userguide.css');</style>

+<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />

+

+<script type="text/javascript" src="../nav/nav.js"></script>

+<script type="text/javascript" src="../nav/prototype.lite.js"></script>

+<script type="text/javascript" src="../nav/moo.fx.js"></script>

+<script type="text/javascript">

+window.onload = function() {

+	myHeight = new fx.Height('nav', {duration: 400});

+	myHeight.hide();

+}

+</script>

+

+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

+<meta http-equiv='expires' content='-1' />

+<meta http-equiv= 'pragma' content='no-cache' />

+<meta name='robots' content='all' />

+<meta name='author' content='Rick Ellis' />

+<meta name='description' content='CodeIgniter User Guide' />

+

+</head>

+<body>

+

+<!-- START NAVIGATION -->

+<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>

+<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle.jpg" width="153" height="44" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>

+<div id="masthead">

+<table cellpadding="0" cellspacing="0" border="0" style="width:100%">

+<tr>

+<td><h1>CodeIgniter User Guide Version 1.5.4</h1></td>

+<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>

+</tr>

+</table>

+</div>

+<!-- END NAVIGATION -->

+

+

+<!-- START BREADCRUMB -->

+<table cellpadding="0" cellspacing="0" border="0" style="width:100%">

+<tr>

+<td id="breadcrumb">

+<a href="http://www.codeigniter.com/">CodeIgniter Home</a> &nbsp;&#8250;&nbsp;

+<a href="../index.html">User Guide Home</a> &nbsp;&#8250;&nbsp;

+Upgrading from 1.5.3 to 1.5.4

+</td>

+<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide&nbsp; <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" />&nbsp;<input type="submit" class="submit" name="sa" value="Go" /></form></td>

+</tr>

+</table>

+<!-- END BREADCRUMB -->

+

+<br clear="all" />

+

+

+<!-- START CONTENT -->

+<div id="content">

+

+<h1>Upgrading from 1.5.4 to 1.5.5</h1>

+

+<p>Before performing an update you should take your site offline by replacing the index.php file with a static one.</p>

+

+

+

+<h2>Step 1: Update your CodeIgniter files</h2>

+

+<p>Replace these files and directories in your "system" folder with the new versions:</p>

+

+<ul>

+

+<li><dfn>system/codeigniter</dfn></li>

+<li><dfn>system/database</dfn></li>

+<li><dfn>system/helpers</dfn></li>

+<li><dfn>system/libraries</dfn></li>

+<li><dfn>system/plugins</dfn></li>

+</ul>

+

+<p class="important"><strong>Note:</strong> If you have any custom developed files in these folders please make copies of them first.</p>

+

+<h2>Step 2: Add time_to_update to your config.php </h2>

+<p>Add the following to system/application/config/config.php with the other </p>

+<code>$config['sess_time_to_update'] 		= 300;</code>

+<h2>Step 3: Update your user guide</h2>

+<p>Please also replace your local copy of the user guide with the new version.</p>

+

+</div>

+<!-- END CONTENT -->

+

+

+<div id="footer">

+<p>

+Previous Topic:&nbsp;&nbsp;<a href="index.html">Installation Instructions</a>

+&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;

+<a href="#top">Top of Page</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;

+<a href="../index.html">User Guide Home</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;

+Next Topic:&nbsp;&nbsp;<a href="../overview/at_a_glance.html">CodeIgniter at a Glance</a>

+</p>

+<p><a href="http://www.codeigniter.com">CodeIgniter</a> &nbsp;&middot;&nbsp; Copyright &#169; 2007 &nbsp;&middot;&nbsp; <a href="http://ellislab.com/">Ellislab, Inc.</a></p>

+</div>

+

+</body>

+</html>
\ No newline at end of file