Header Back

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Zeceer
Forum Contributor
Posts: 136
Joined: Fri Aug 02, 2002 5:10 am
Location: Norway

Header Back

Post 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);
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post by qartis »

Code: Select all

<?
$back = $HTTP_REFERER;
header("Location: $back");
?>
User avatar
Zeceer
Forum Contributor
Posts: 136
Joined: Fri Aug 02, 2002 5:10 am
Location: Norway

Post 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
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post by qartis »

Try

Code: Select all

$_SERVER["HTTP_REFERER"]
User avatar
Zeceer
Forum Contributor
Posts: 136
Joined: Fri Aug 02, 2002 5:10 am
Location: Norway

Post by Zeceer »

Thats it :D . Thanx. The problem error I got there first was because of the global vatiables?
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post 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?
User avatar
Zeceer
Forum Contributor
Posts: 136
Joined: Fri Aug 02, 2002 5:10 am
Location: Norway

Post 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.
Post Reply