dchill42 avatar dchill42 committed 55d907b

Added sess_regenerate() feature

Comments (0)

Files changed (3)

system/libraries/Session/Session.php

 	}
 
 	/**
+	 * Regenerate the current session
+	 *
+	 * @access  public
+	 * @param   $destroy	boolean - Destroy session data flag (default: false)
+	 * @return  void
+	 */
+	public function sess_regenerate($destroy = false) {
+		// Just call regenerate on driver
+		$this->current->sess_regenerate($destroy);
+	}
+
+	/**
 	 * Fetch a specific item from the session array
 	 *
 	 * @access  public
 	abstract public function sess_destroy();
 
 	/**
+	 * Regenerate the current session
+	 *
+	 * Regenerate the session id
+	 * The child class MUST implement this abstract method!
+	 *
+	 * @access  public
+	 * @param   $destroy	boolean - Destroy session data flag (default: false)
+	 * @return  void
+	 */
+	abstract public function sess_regenerate($destroy = false);
+
+	/**
 	 * Get a reference to user data array
 	 *
 	 * Give array access to the main Session object

system/libraries/Session/drivers/Session_cookie.php

 	// --------------------------------------------------------------------
 
 	/**
+	 * Regenerate the current session
+	 *
+	 * Regenerate the session id
+	 *
+	 * @access  public
+	 * @param   $destroy	boolean - Destroy session data flag (default: false)
+	 * @return  void
+	 */
+	public function sess_regenerate($destroy = false) {
+		// Check destroy flag
+		if ($destroy) {
+			// Destroy old session and create new one
+			$this->sess_destroy();
+			$this->_sess_create();
+		}
+		else {
+			// Just force an update to recreate the id
+			$this->_sess_update(true);
+		}
+	}
+
+	// --------------------------------------------------------------------
+
+	/**
 	 * Get a reference to user data array
 	 *
 	 * @access  public
 	 * Update an existing session
 	 *
 	 * @access  private
+	 * @param   $force  boolean - Force update flag (default: false)
 	 * @return  void
 	 */
-	private function _sess_update() {
-		// We only update the session every five minutes by default
-		if (($this->userdata['last_activity'] + $this->sess_time_to_update) >= $this->now()) {
+	private function _sess_update($force = false) {
+		// We only update the session every five minutes by default (unless forced)
+		if (!$force && ($this->userdata['last_activity'] + $this->sess_time_to_update) >= $this->now()) {
 			return;
 		}
 

system/libraries/Session/drivers/Session_native.php

 	}
 
 	/**
+	 * Regenerate the current session
+	 *
+	 * Regenerate the session id
+	 *
+	 * @access  public
+	 * @param   $destroy	boolean - Destroy session data flag (default: false)
+	 * @return  void
+	 */
+	public function sess_regenerate($destroy = false) {
+		// Just regenerate id, passing destroy flag
+		session_regenerate_id($destroy);
+	}
+
+	/**
 	 * Get a reference to user data array
 	 *
 	 * @access  public
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.