Capture IP and URL of referrer
You are almost there, here is a rewritten version of your code that should work:

&lt;?php

/**
 * @file
 * Store access data.
 */

use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;

$autoloader = require_once 'autoload.php';

$request = Request::createFromGlobals();
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod');
$kernel-&gt;boot();

$client_ip = $request-&gt;getClientIP();
$headers = $request-&gt;server-&gt;getHeaders();
$referer_url = isset($headers['HTTP_REFERER']) ? $headers['HTTP_REFERER'] : '';

\Drupal::logger('sitelog')-&gt;notice($referer_url . '::' . $client_ip);


The main idea of the rewrite is to keep a reference to the HttpFoundation\Request from the very beginning and use if to get access to the parameters you want.

P.S.: Loading Symfony's components as well as booting Drupal's kernel may be an overkill for getting the client's IP and referer url, a simple php script could do that for you and write logs in a file.