title: $_SERVER['HTTP_REFERER'] and cookies
body: <p>I read, both on SO and other sites, that <code>$_SERVER['HTTP_REFERER']</code> is something we, as programmers, should always avoid. Reading the PHP manual we encounter these lines:</p>
  
  <blockquote>
    <p>The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.</p>
  </blockquote>
  
  <p>Considering "user agents" things such as Web Browser (Safari, Chrome, Opera, Firefox, basically they are all), the manual tell us that this variable may be changed by them.
  Here it comes my first question:</p>
  
  <blockquote>
    <p><strong>Question 1</strong>: Why should "users agent" modify this parameter? What are the reason for a web browser not to set this parameter?</p>
  </blockquote>
  
  <p>It's just inquisitiveness, and i'll not use <code>$_SERVER['HTTP_REFERER']</code>.
  From my latest statement, it's oblivious that, if we do need of such a function, we need to figure something out. The first thing that comes in my mind is a cookie solution, in which we do something like:</p>
  
  <pre><code>setcookie('latest_page', __FILE__, 60 * 60 * 24 * 7);
  </code></pre>
  
  <p>And then, based on how you prefer to do it, you can recover what you need.
  Here it comes the second and last question:</p>
  
  <blockquote>
    <p><strong>Question 2</strong>: Is this way the best? Are there any way to improve it?</p>
  </blockquote>