Page 1 of 1
Redirect Page but KEEP HTTP_REFERER working ???
Posted: Wed Jun 28, 2006 7:13 pm
by hookgr
Hello guys,
I am on page a.php and need to send user to b.php.
If I give him an href to click, on b.php I can get as $_SERVER['HTTP_REFERER'] the
http://domain/a.php value.
If I send him to b.php with header "Location" or "Refresh", b.php has BLANK / EMPTY HTTP_REFERER...
How can I automatically send user to b.php but keep HTTP_REFERER working ???
Posted: Wed Jul 12, 2006 11:30 pm
by Benjamin
Untested
a.php
Code: Select all
session_start();
$_SESSION['referrer'] = $_SERVER['HTTP_REFERER'];
// header redirect...
b.php
Code: Select all
session_start();
$referrer = $_SESSION['referrer'];
and yet another way...
a.php
Code: Select all
header("Location: http://sitename.com/b.php?referrer=" . $_SERVER['HTTP_REFERER']);
b.php
Posted: Wed Jul 12, 2006 11:38 pm
by John Cartwright
It is bad practice to rely on http_refferer to exist, as it likely won't for a large proportion of the time. Might want to look into alternatives, such as saving the "page name" during each page access, and checking against that on any new page hits.
Posted: Thu Jul 13, 2006 4:41 am
by hookgr
i dont mean how i can pass between the two scripts the variable referer or the data, i know about sessions and lot other methods.
the problem is what b.php itself detects as referer...
when you do header Location redirect, REFERER field is blank, and i want it to appear as if user has clicked a link to go to b.php
Posted: Thu Jul 13, 2006 4:50 am
by ok
The PHP manual says:
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.
"... it cannot really be trusted."!!!
What you want to do with the 'HTTP_REFERER' info???
Posted: Thu Jul 13, 2006 5:34 am
by Jenk
hookgr wrote:i dont mean how i can pass between the two scripts the variable referer or the data, i know about sessions and lot other methods.
the problem is what b.php itself detects as referer...
when you do header Location redirect, REFERER field is blank, and i want it to appear as if user has clicked a link to go to b.php
The answer: No. Not possible.
astions has provided you with alternatives, if they are not good enough, then what you seek is not possible.