function WriteSafeSessionHandler::write

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Session/WriteSafeSessionHandler.php \Drupal\Core\Session\WriteSafeSessionHandler::write()
  2. 10 core/lib/Drupal/Core/Session/WriteSafeSessionHandler.php \Drupal\Core\Session\WriteSafeSessionHandler::write()
  3. 9 core/lib/Drupal/Core/Session/WriteSafeSessionHandler.php \Drupal\Core\Session\WriteSafeSessionHandler::write()
  4. 8.9.x core/lib/Drupal/Core/Session/WriteSafeSessionHandler.php \Drupal\Core\Session\WriteSafeSessionHandler::write()

File

core/lib/Drupal/Core/Session/WriteSafeSessionHandler.php, line 52

Class

WriteSafeSessionHandler
Wraps the session handler to prevent writes when not necessary or allowed.

Namespace

Drupal\Core\Session

Code

public function write(#[\SensitiveParameter] string $session_id, string $session_data) : bool {
  // Only write the session when it has been modified.
  if (isset($this->readSessions[$session_id]) && $this->readSessions[$session_id] === $session_data) {
    return TRUE;
  }
  if ($this->isSessionWritable()) {
    return $this->handler
      ->write($session_id, $session_data);
  }
  return TRUE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.