Reputation: 2193
Before reading my question, please note: I am aware that HTTP_REFERER can be spoofed or disabled in the client browser. I don't care for my use case, and the browser I am testing with definitely passes referer information.
My question is this:
I create a file called page1.php:
<?php
header("Location: page2.php");
I create a second file called page2.php:
<?php
echo "Referred by \"" . $_SERVER['HTTP_REFERER'] . "\"";
then from my client browser I call:
and I am expecting the resultant output from page2.php to be:
Referred by "http://test-me.co/page1.php"
but instead it displays with no referer information as follows:
Referred by ""
Can anyone please enlighten me as to why referer is empty?
thanks so much!
Upvotes: 1
Views: 1497
Reputation: 522015
The referer contains the last actual page the user visited. If you enter URL example.com/a.html
into your address bar which immediately redirects to /b.html
, then you never really visited a.html
at all; and before that there's no page you "came from".
To see any referer after a redirect the redirecting page must have been linked from somewhere, i.e.
a.html --link--> b.html --redirect--> c.html
Then in c.html
you'd see a.html
as the referer. If you're starting this chain at b.html
, there is no referer.
Upvotes: 5