Redirecting a user back to where they came from

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
hibbeac1
Forum Newbie
Posts: 13
Joined: Thu Oct 30, 2003 10:25 am

Redirecting a user back to where they came from

Post by hibbeac1 »

Hi,

I was wandering how to redirect users back to where they came from if they go to a page that they do not have access to. They won't always come from the same page of course.

Thanks again
markbeadle
Forum Commoner
Posts: 29
Joined: Tue Dec 02, 2003 2:50 am
Location: Aachen, Germany

Post by markbeadle »

Use global value $HTTP_REFERER
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

$HTTP_REFERER is deprecated, use $_SERVER["HTTP_REFERER"] instead.

Or use js: history.go(-1)
hibbeac1
Forum Newbie
Posts: 13
Joined: Thu Oct 30, 2003 10:25 am

Post by hibbeac1 »

I've tried doing this but it didn't work. It came up with the can't find page error. This is how i tried to do it.

header ("Location: http:// . $_SERVER['HTTP_REFERRER']");
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

hibbeac1 wrote:I've tried doing this but it didn't work. It came up with the can't find page error. This is how i tried to do it.

header ("Location: http:// . $_SERVER['HTTP_REFERER']");

Code: Select all

header("Location: ".$_SERVER['HTTP_REFERER']);
//or
header("Location: {$_SERVER['HTTP_REFERER']}");
[Changed REFERRER -typo to REFERER --JAM]
Thanks, Jam, I missed the double R
Last edited by Weirdan on Fri Dec 05, 2003 12:36 pm, edited 1 time in total.
Chambrln
Forum Commoner
Posts: 43
Joined: Tue Dec 02, 2003 10:45 am
Location: Oregon

Post by Chambrln »

If you are using Dreamweaver MX (not MX 2004) to code and you use the auto complete function for HTTP_REFERER it has a typo and puts in an extra R giving you HTTP_REFERRER
Post Reply