Exemplo n.º 1
0
 public function write($sessionId, $serializedData)
 {
     try {
         // For performance reasons, do not update the sessions table, unless
         // $_SESSION has changed or more than 180 has passed since the last update.
         if ($this->sessionDataHasChanged($sessionId, $serializedData)) {
             // Either ssid or sid or both will be added from $key below.
             $fields = array('uid' => $this->uid, 'cache' => 0, 'hostname' => ip_address(), 'session' => $serializedData, 'timestamp' => REQUEST_TIME);
             $key = array('sid' => $sessionId, 'ssid' => '');
             db_merge('sessions')->key($key)->fields($fields)->execute();
         }
         return TRUE;
     } catch (Exception $exception) {
         // FIXME: This should never be here, a global try/catch should definitely
         // be done upper in the code.
         require_once DRUPAL_ROOT . '/includes/errors.inc';
         // If we are displaying errors, then do so with no possibility of a further
         // uncaught exception being thrown.
         if (error_displayable()) {
             print '<h1>Uncaught exception thrown in session handler.</h1>';
             print '<p>' . _drupal_render_exception_safe($exception) . '</p><hr />';
         }
         return FALSE;
     }
 }
Exemplo n.º 2
0
 public function write($sessionId, $serializedData)
 {
     global $user;
     try {
         // For performance reasons, do not update the sessions table, unless
         // $_SESSION has changed or more than 180 has passed since the last update.
         if ($this->sessionDataHasChanged($sessionId, $serializedData)) {
             $cid = $this->getCid($sessionId);
             // Either ssid or sid or both will be added from $key below.
             $data = new stdClass();
             $data->uid = $this->uid;
             $data->session = $serializedData;
             $this->cacheBackend->set($cid, $data);
         }
         return TRUE;
     } catch (Exception $exception) {
         // FIXME: This should never be here, a global try/catch should definitely
         // be done upper in the code.
         require_once DRUPAL_ROOT . '/includes/errors.inc';
         // If we are displaying errors, then do so with no possibility of a further
         // uncaught exception being thrown.
         if (error_displayable()) {
             print '<h1>Uncaught exception thrown in session handler.</h1>';
             print '<p>' . _drupal_render_exception_safe($exception) . '</p><hr />';
         }
         return FALSE;
     }
 }
 /**
  * Writes an entire session to the database (internal use only).
  *
  * This function is registered with session_set_save_handler() to support
  * database-backed sessions.
  *
  * This function is an internal function and must not be called directly.
  * Doing so may result in corrupted session data or other unexpected behavior.
  * Session data must always be accessed via the $_SESSION superglobal.
  *
  * @param string $sid
  *                      The session ID of the session to write to.
  * @param string $value
  *                      Session data to write as a serialized string.
  *
  * @return bool Always returns TRUE.
  */
 public function write($sid, $value)
 {
     global $user;
     // The exception handler is not active at this point, so we need to do it
     // manually.
     try {
         if (!drupal_save_session()) {
             // We don't have anything to do if we are not allowed to save the session.
             return;
         }
         // Either ssid or sid or both will be added from $key below.
         $fields = array('uid' => $user->uid, 'cache' => isset($user->cache) ? $user->cache : 0, 'hostname' => ip_address(), 'session' => $value, 'timestamp' => REQUEST_TIME);
         // Use the session ID as 'sid' and an empty string as 'ssid' by default.
         // _drupal_session_read() does not allow empty strings so that's a safe
         // default.
         $key = array('sid' => $sid, 'ssid' => '');
         // On HTTPS connections, use the session ID as both 'sid' and 'ssid'.
         unset($key['ssid']);
         db_merge('sessions')->key($key)->fields($fields)->execute();
         // Likewise, do not update access time more than once per 180 seconds.
         if ($user->uid) {
             db_update('users')->fields(array('access' => REQUEST_TIME))->condition('uid', $user->uid)->execute();
         }
         return TRUE;
     } catch (\Exception $exception) {
         require_once DRUPAL_ROOT . '/includes/errors.inc';
         // If we are displaying errors, then do so with no possibility of a further
         // uncaught exception being thrown.
         if (error_displayable()) {
             print '<h1>Uncaught exception thrown in session handler.</h1>';
             print '<p>' . _drupal_render_exception_safe($exception) . '</p><hr />';
         }
         return FALSE;
     }
 }