Esempio n. 1
0
 /**
  * write the current session
  *
  * @access	public
  * @return	void
  */
 public function write()
 {
     parent::write();
     // do we have something to write?
     if (!empty($this->keys)) {
         // rotate the session id if needed
         $this->rotate(false);
         // then update the cookie
         $this->_set_cookie(array($this->data, $this->flash));
     }
 }
Esempio n. 2
0
 /**
  * write the current session
  *
  * @access	public
  * @return	Fuel\Core\Session_Cookie
  */
 public function write()
 {
     parent::write();
     // do we have something to write?
     if (!empty($this->keys) or !empty($this->data) or !empty($this->flash)) {
         // create the session if it doesn't exist
         empty($this->keys) and $this->create();
         // rotate the session id if needed
         $this->rotate(false);
         // then update the cookie
         $this->_set_cookie(array($this->data, $this->flash));
     }
     return $this;
 }
Esempio n. 3
0
 /**
  * write the session
  *
  * @access	public
  * @return	void
  */
 public function write()
 {
     // do we have something to write?
     if (!empty($this->keys)) {
         parent::write();
         // rotate the session id if needed
         $this->rotate(false);
         // session payload
         $payload = $this->_serialize(array($this->data, $this->flash));
         // create the session file
         $this->_write_redis($this->keys['session_id'], $payload);
         // was the session id rotated?
         if (isset($this->keys['previous_id']) && $this->keys['previous_id'] != $this->keys['session_id']) {
             // point the old session file to the new one, we don't want to lose the session
             $payload = $this->_serialize(array('rotated_session_id' => $this->keys['session_id']));
             $this->_write_redis($this->keys['previous_id'], $payload);
         }
         $this->_set_cookie();
     }
 }
Esempio n. 4
0
 /**
  * write the current session
  *
  * @access	public
  * @return	Fuel\Core\Session_Cookie
  */
 public function write()
 {
     // do we have something to write?
     if (!empty($this->keys) or !empty($this->data) or !empty($this->flash)) {
         parent::write();
         // rotate the session id if needed
         $this->rotate(false);
         // record the last update time of the session
         $this->keys['updated'] = $this->time->get_timestamp();
         // then update the cookie
         $this->_set_cookie(array($this->keys, $this->data, $this->flash));
     }
     return $this;
 }
Esempio n. 5
0
 /**
  * write the current session
  *
  * @access	public
  * @return	Fuel\Core\Session_Db
  */
 public function write()
 {
     // do we have something to write?
     if (!empty($this->keys) or !empty($this->data) or !empty($this->flash)) {
         parent::write();
         // rotate the session id if needed
         $this->rotate(false);
         // record the last update time of the session
         $this->keys['updated'] = $this->time->get_timestamp();
         // add a random identifier, we need the payload to be absolutely unique
         $this->flash[$this->config['flash_id'] . '::__session_identifier__'] = array('state' => 'expire', 'value' => sha1(uniqid(rand(), true)));
         // create the session record, and add the session payload
         $session = $this->keys;
         $session['payload'] = $this->_serialize(array($this->keys, $this->data, $this->flash));
         try {
             // do we need to create a new session?
             if (is_null($this->record)) {
                 // create the new session record
                 list($notused, $result) = \DB::insert($this->config['table'], array_keys($session))->values($session)->execute($this->config['database']);
             } else {
                 // update the database
                 $result = \DB::update($this->config['table'])->set($session)->where('session_id', '=', $this->record->get('session_id'))->execute($this->config['database']);
                 // if it failed, perhaps we have lost a session id due to rotation?
                 if ($result === 0) {
                     // if so, there must be a session record with our session_id as previous_id
                     $result = \DB::select()->where('previous_id', '=', $this->record->get('session_id'))->from($this->config['table'])->execute($this->config['database']);
                     if ($result->count()) {
                         logger(\Fuel::L_WARNING, 'Session update failed, session record recovered using previous id. Lost rotation data?');
                         // update the session data
                         $this->keys['session_id'] = $result->get('session_id');
                         $this->keys['previous_id'] = $result->get('previous_id');
                         // and recreate the payload
                         $session = $this->keys;
                         $session['payload'] = $this->_serialize(array($this->keys, $this->data, $this->flash));
                         // and update the database
                         $result = \DB::update($this->config['table'])->set($session)->where('session_id', '=', $this->keys['session_id'])->execute($this->config['database']);
                     } else {
                         logger(\Fuel::L_ERROR, 'Session update failed, session record could not be recovered using the previous id');
                         $result = false;
                     }
                 }
             }
             // update went well?
             if ($result !== 0) {
                 // then update the cookie
                 $this->_set_cookie(array($this->keys['session_id']));
             }
             // Run garbage collector
             $this->gc();
         } catch (Database_Exception $e) {
             // strip the actual query from the message
             $msg = $e->getMessage();
             $msg = substr($msg, 0, strlen($msg) - strlen(strrchr($msg, ':')));
             // and rethrow it
             throw new \Database_Exception($msg);
         }
     }
     return $this;
 }
Esempio n. 6
0
 /**
  * write the session
  *
  * @access	public
  * @return	Fuel\Core\Session_File
  */
 public function write()
 {
     // do we have something to write?
     if (!empty($this->keys) or !empty($this->data) or !empty($this->flash)) {
         // create the session if it doesn't exist
         empty($this->keys) and $this->create();
         parent::write();
         // rotate the session id if needed
         $this->rotate(false);
         // session payload
         $payload = $this->_serialize(array($this->data, $this->flash));
         // create the session file
         $this->_write_file($this->keys['session_id'], $payload);
         // was the session id rotated?
         if (isset($this->keys['previous_id']) and $this->keys['previous_id'] != $this->keys['session_id']) {
             // point the old session file to the new one, we don't want to lose the session
             $payload = $this->_serialize(array('rotated_session_id' => $this->keys['session_id']));
             $this->_write_file($this->keys['previous_id'], $payload);
         }
         $this->_set_cookie();
         // do some garbage collection
         if (mt_rand(0, 100) < $this->config['gc_probability']) {
             if ($handle = opendir($this->config['path'])) {
                 $expire = $this->time->get_timestamp() - $this->config['expiration_time'];
                 while (($file = readdir($handle)) !== false) {
                     if (filetype($this->config['path'] . $file) == 'file' and strpos($file, $this->config['cookie_name'] . '_') === 0 and filemtime($this->config['path'] . $file) < $expire) {
                         @unlink($this->config['path'] . $file);
                     }
                 }
                 closedir($handle);
             }
         }
     }
     return $this;
 }
Esempio n. 7
0
 /**
  * write the current session
  *
  * @access public
  * @return Fuel\Core\Session_Db
  */
 public function write()
 {
     // do we have something to write?
     if (!empty($this->keys) or !empty($this->data) or !empty($this->flash)) {
         parent::write();
         // rotate the session id if needed
         $this->rotate(false);
         // record the last update time of the session
         $this->keys['updated'] = $this->time->get_timestamp();
         // create the session record, and add the session payload
         $session = $this->keys;
         $session['payload'] = $this->_serialize(array($this->keys, $this->data, $this->flash));
         // do we need to create a new session?
         if (is_null($this->record)) {
             // create the new session record
             $result = \DB::insert($this->config['table'], array_keys($session))->values($session)->execute($this->config['database']);
         } else {
             // update the database
             $result = \DB::update($this->config['table'])->set($session)->where('session_id', '=', $this->record->get('session_id'))->execute($this->config['database']);
         }
         // update went well?
         if ($result !== false) {
             // then update the cookie
             $this->_set_cookie(array($this->keys['session_id']));
         } else {
             logger(\Fuel::L_ERROR, 'Session update failed, session record could not be found. Concurrency issue?');
         }
         // do some garbage collection
         if (mt_rand(0, 100) < $this->config['gc_probability']) {
             $expired = $this->time->get_timestamp() - $this->config['expiration_time'];
             $result = \DB::delete($this->config['table'])->where('updated', '<', $expired)->execute($this->config['database']);
         }
     }
     return $this;
 }
Esempio n. 8
0
 /**
  * write the session
  *
  * @access	public
  * @return	Fuel\Core\Session_Memcached
  */
 public function write()
 {
     // do we have something to write?
     if (!empty($this->keys) or !empty($this->data) or !empty($this->flash)) {
         parent::write();
         // rotate the session id if needed
         $this->rotate(false);
         // record the last update time of the session
         $this->keys['updated'] = $this->time->get_timestamp();
         // session payload
         $payload = $this->_serialize(array($this->keys, $this->data, $this->flash));
         // create the session file
         $this->_write_memcached($this->keys['session_id'], $payload);
         // was the session id rotated?
         if (isset($this->keys['previous_id']) and $this->keys['previous_id'] != $this->keys['session_id']) {
             // point the old session file to the new one, we don't want to lose the session
             $payload = $this->_serialize(array('rotated_session_id' => $this->keys['session_id']));
             $this->_write_memcached($this->keys['previous_id'], $payload);
         }
         $this->_set_cookie(array($this->keys['session_id']));
     }
     return $this;
 }