Php Access User Data from external script
You can following file authorize.php to do it like this: 

&lt;?php
use Drupal\Core\DrupalKernel;
use Drupal\Core\Site\Settings;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;

$autoloader = require_once 'autoload.php';

function authorize_access_allowed(Request $request) {
  $account = \Drupal::service('authentication')-&gt;authenticate($request);
  if ($account) {
    \Drupal::currentUser()-&gt;setAccount($account);
  }
  return Settings::get('allow_authorize_operations', TRUE) &amp;&amp; \Drupal::currentUser()-&gt;hasPermission('administer software updates');
}

try {
  $request = Request::createFromGlobals();
  $kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod');
  $kernel-&gt;prepareLegacyRequest($request);
}
catch (HttpExceptionInterface $e) {
  $response = new Response('', $e-&gt;getStatusCode());
  $response-&gt;prepare($request)-&gt;send();
  exit;
}

authorize_access_allowed($request);
$user = Drupal::currentUser();

if ($user-&gt;id()) {
    print "Logged in";
} else {
   print "Logged out";
}