$_SERVER are server variables, so pretty much every variable could be different in that array, considering the wide variety of web servers: Apache, Nginx, Lighthttpd just to name a few…
I have just ran some brief tests using $_SERVER[“HTTP_REFERER”] variable and it works fine but also produces an error if there was not a previous page.
Try the following and see what specific Linux Server variables are shown for different scenarios.
...
...
...
<pre style='width:88%; margin:3em auto; color:#f00; background-color: pink;'>
<h3>$_SERVER;</h3>
<?php
print_r( $_SERVER );
// if set could also be interesting
if( isset($_SESSION) )
{
echo '<h3>$_SESSION</h3>';
print_r( $_SESSION );
}
?>
</pre>
<body>
</html>
The HTTP_REFERER server variable is not set the first time your site is called from the browser command line. It is only set when called from another web page. If you do not test for the variable, using isset( $_SESSION[‘HTP_REFERER’] ) then an error will be produced.
That is exactly how HTTP_REFERER works. You won’t get it on the initial page load, but subsequent page interactions “should” contain it. Granted, it can be spoofed (just like most SERVER, GET, POST, and REQUEST variables can be spoofed). So you shouldn’t rely on it, and you should ALWAYS validate it before using it.
If you write to it before it exists or before reading it, then you can never get the referring page because you just overwrote that value. So you have to read it first and then write to it.