$_SERVER['HTTP_REFERER'] not working with Header
<p>I have a site that allows public access to some pages, but requires a login for others. I have a link to the login from all pages, and what I'd like to do after a successful login is send the user back to the page they were on when they clicked the login link. I know the HTTP_REFERER can be spoofed, and sometimes stripped out by certain hosts and proxies, but since it's strictly within my own site, and only a convenience for users, I'm not too worried about it. </p>

<p>I am curious about why it isn't working in conjunction with a redirect, though. I've set a visible field to contain the value of the http referer, and it displays correctly. So the page is getting the value of the referrer variable. But when I try this:</p>

<pre><code>$home_url =  $_SERVER['HTTP_REFERER'];
header('Location: ' . $home_url);
</code></pre>

<p>it doesn't work. This, on the other hand, does:</p>

<pre><code>$home_url = 'http://' . $_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/discussions.php';
header('Location: ' . $home_url);
</code></pre>

<p>So I know the header location part works. Any idea why it doesn't want to work in conjunction with the http_referer variable? </p>

<p>(Also, does it drive anyone else nuts that referer is spelled incorrectly? I keep mistyping it using the OED spelling, silly me...)</p>
