How does Drupal verify sessions from the cookie value? Sorry, I know it's weird, but I'm trying to integrate another php application with Drupal.  I want to know if the user is currently logged in to the Drupal site, even though the request is going elsewhere.  I'm getting the cookie out of a Guzzle request object.  As far as the application is concerned (because of Nginx proxying), the origin is the same, and the cookie is getting passed successfully.

Here's what I'm getting out of the Guzzle request object:

array(1) {
  ["SSESSdbf18a05343cfb88719ee68ff6159a52"]=&gt;
  string(43) "5eW8YPdDPjojAjuokObuD5R2L7cyOfffmBuVAdHzWwU"
}


The above value is also what the browser reports.

But, in my sessions table in the DB, there is no session that resembles this, either in the sid or the session column.

How does Drupal check the DB for a valid session cookie, and where should I be looking in core to copy this?
I figured it out, but if someone posts a more in-depth answer, I'll accept it.

Drupal has a SessionHandler with a read function:

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


And, if you bootstrap Drupal, or call an external Drush script, you can do this:

$session_handler = \Drupal::getContainer()-&gt;get('session_handler.storage');
$logged_in = (bool) $session_handler-&gt;read($session);


Here's how I got the cookie out of the Guzzle object:

$request-&gt;getCookies();
//var_dump($cookies);
foreach($cookies as $cookie){
  if(strpos($cookie, "SESS") == 0){
    $session = $cookie;
  }
}


If you actually want the UID, you're going to have to not do the (bool) cast and de-blob the thing, because it returns the raw MySQL data.