function SessionHandler::read

Same name in other branches
  1. 9 core/lib/Drupal/Core/Session/SessionHandler.php \Drupal\Core\Session\SessionHandler::read()
  2. 8.9.x core/lib/Drupal/Core/Session/SessionHandler.php \Drupal\Core\Session\SessionHandler::read()
  3. 11.x core/lib/Drupal/Core/Session/SessionHandler.php \Drupal\Core\Session\SessionHandler::read()

File

core/lib/Drupal/Core/Session/SessionHandler.php, line 63

Class

SessionHandler
Default session handler.

Namespace

Drupal\Core\Session

Code

public function read(string $sid) : string|false {
    $data = '';
    if (!empty($sid)) {
        try {
            // Read the session data from the database.
            $query = $this->connection
                ->queryRange('SELECT [session] FROM {sessions} WHERE [sid] = :sid', 0, 1, [
                ':sid' => Crypt::hashBase64($sid),
            ]);
            $data = (string) $query->fetchField();
        } catch (\Exception) {
        }
    }
    return $data;
}

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