Changeset 153
- Timestamp:
- 01/25/07 18:00:46 (2 years ago)
- Files:
-
- trunk/src/main/php/net/stubbles/ipo/session/stubBaseSession.php (modified) (7 diffs)
- trunk/src/main/php/net/stubbles/ipo/session/stubPHPSession.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/ipo/session/stubSession.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/ipo/IPOTestSuite.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/ipo/session (added)
- trunk/src/test/php/net/stubbles/ipo/session/stubBaseSessionTestCase.php (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/ipo/session/stubBaseSession.php
r138 r153 1 1 <?php 2 2 /** 3 * interface for sessions3 * Base class for session implementations. 4 4 * 5 5 * @author Frank Kleine <mikey@stubbles.net> … … 9 9 stubClassLoader::load('net.stubbles.ipo.session.stubSession'); 10 10 /** 11 * interface for sessions 11 * Base class for session implementations. 12 * 13 * This class offers a basic implementation for session handling, mainly for 14 * the default values of a session which are the start time of the session, 15 * the fingerprint of the user and the token of the current and the next 16 * request. While a concrete instance is created the class checks the session 17 * to prevent the user against session fixation and session hijacking. 12 18 * 13 19 * @package stubbles 14 20 * @subpackage ipo_session 15 * @todo create test16 21 */ 17 22 abstract class stubBaseSession extends stubBaseObject implements stubSession … … 43 48 protected final function __construct($sessionName) 44 49 { 45 $this->doConst uct($sessionName);50 $this->doConstruct($sessionName); 46 51 47 52 if ($this->hasValue(stubSession::START_TIME) == false || $this->doGetValue(stubSession::FINGERPRINT) != $this->getFingerprint()) { … … 55 60 56 61 $this->putValue(stubSession::START_TIME, time()); 57 $this->isNew = true;58 $this->putValue(stubSession::FINGERPRINT, $this->getFingerprint());59 $this->token = md5(uniqid(rand()));60 } else {61 $this->token = $this->doGetValue(stubSession::NEXT_TOKEN);62 }63 64 $this->putValue(stubSession::NEXT_TOKEN, md5(uniqid(rand())));62 $this->isNew = true; 63 $this->putValue(stubSession::FINGERPRINT, $this->getFingerprint()); 64 $this->token = md5(uniqid(rand())); 65 } else { 66 $this->token = $this->doGetValue(stubSession::NEXT_TOKEN); 67 } 68 69 $this->putValue(stubSession::NEXT_TOKEN, md5(uniqid(rand()))); 65 70 } 66 71 … … 202 207 * removes a value from the session 203 208 * 204 * @param string $key key where value is stored under 209 * @param string $key key where value is stored under 210 * @return bool true if value existed and was removed, else false 205 211 * @throws stubSessionException 206 212 */ … … 212 218 213 219 if ($this->hasValue($key) == true) { 214 $this->doRemoveValue($key); 215 } 220 return $this->doRemoveValue($key); 221 } 222 223 return false; 216 224 } 217 225 … … 219 227 * removes a value from the session 220 228 * 221 * @param string $key key where value is stored under 229 * @param string $key key where value is stored under 230 * @return bool true if value existed and was removed, else false 222 231 */ 223 232 protected abstract function doRemoveValue($key); trunk/src/main/php/net/stubbles/ipo/session/stubPHPSession.php
r138 r153 64 64 { 65 65 $this->reset(); 66 @session_destroy();67 @session_start();66 @session_destroy(); 67 @session_start(); 68 68 } 69 69 … … 114 114 * removes a value from the session 115 115 * 116 * @param string $key key where value is stored under 116 * @param string $key key where value is stored under 117 * @return bool true if value existed and was removed, else false 117 118 */ 118 119 protected function doRemoveValue($key) 119 120 { 120 121 unset($_SESSION[$key]); 122 return true; 121 123 } 122 124 trunk/src/main/php/net/stubbles/ipo/session/stubSession.php
r138 r153 74 74 75 75 /** 76 * switch for disabling creation of a new token77 *78 * @param bool $recreateToken FALSE if no new token should be created79 */80 public function recreateToken($recreateToken);81 82 /**83 76 * checks if this session is valid 84 77 * … … 129 122 * 130 123 * @param string $key key where value is stored under 124 * @return bool true if value existed and was removed, else false 131 125 * @throws stubSessionException 132 126 */ trunk/src/test/php/net/stubbles/ipo/IPOTestSuite.php
r113 r153 34 34 35 35 $this->addTestFile($dir . '/response/stubCookieTestCase.php'); 36 37 $this->addTestFile($dir . '/session/stubBaseSessionTestCase.php'); 36 38 } 37 39 }
