title: HTTP_REFERER not getting saved in a session
body: <p>I know HTTP_REFERER can be spoofed, but it does the job perfectly the way we want it now. Except I can't get the first referrer to be saved in a session, so entering from domain.com works, but going to another page will be blocked cause the HTTP_REFERER changes into our own domain. Below is my code hopefully someone can help me out.</p>
  
  <pre><code>&lt;?php
  // Start the session
  if (session_status() == PHP_SESSION_NONE) {
      session_start();
  }
  ?&gt;
  
  &lt;?php
  // Getting referer and saving
  $server = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
  $referer = parse_url($server);
  $refererhost = isset($referer['host']) ? $referer['host'] : '';
  $_SESSION['originalref'] = $refererhost;
  ?&gt;
  
  &lt;?php if ($_SESSION['originalref'] == 'domain.com'): ?&gt;
  
  &lt;!doctype html&gt;
  &lt;html&gt;
      &lt;head&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;p&gt;Allowed.&lt;/p&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  
  &lt;?php else: ?&gt;
  
  &lt;!doctype html&gt;
  &lt;html&gt;
      &lt;head&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;p&gt;Not allowed. Debug: &lt;?= $_SESSION['originalref'] ?&gt;&lt;/p&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  
  &lt;?php endif; ?&gt;
  </code></pre>
  
  <p>Edit: I made the HTML output in the statements simpler, normally a complete site will be loaded and this is the root template.</p>