Page 1 of 1
Header Back
Posted: Sat Jun 28, 2003 3:51 am
by Zeceer
Is it possible to send a user one page back by using header? At this point i'm using meta to perform this task, but that doesn't work with other browsers than IE.
I nees something in PHP that does the same as this: javascript:history.go(-1);
Posted: Sat Jun 28, 2003 3:58 am
by qartis
Code: Select all
<?
$back = $HTTP_REFERER;
header("Location: $back");
?>
Posted: Sat Jun 28, 2003 4:08 am
by Zeceer
For some kind og reason that didn't work? Added it in the bottom of my script, but only get this:
Code: Select all
Notice: Undefined variable: HTTP_REFERER
Posted: Sat Jun 28, 2003 4:09 am
by qartis
Posted: Sat Jun 28, 2003 4:12 am
by Zeceer
Thats it

. Thanx. The problem error I got there first was because of the global vatiables?
Posted: Sat Jun 28, 2003 4:24 am
by qartis
It depends, were you using that header via a function?
Code: Select all
function back(){
$back = $HTTP_REFERER;
header("Location: $back");
}
back();
If so, then you'd need to
Code: Select all
function back(){
***global $HTTP_REFERER;***
$back = $HTTP_REFERER;
header("Location: $back");
}
To allow back() to access it, although note that $_SERVER['HTTP_REFERER'] is more reliable, and is superglobal.
(Asterisks used only because [ b ] isn't working properly right now.)
I might be straying a bit off-topic here, but I'm wondering: are you trying to have php code execute, but the user remain at the same page afterwards?
Posted: Sat Jun 28, 2003 5:33 am
by Zeceer
It's a shopping a shopping cart. When the user clicks the delete button on a product, he's sent to a script that unsets the array containing the product, and then sends the user back to where he came from. It then looks like the page refresh and the product is gone.
I use same thing when adding a product.