Getting last page visited

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
Sid3335
Forum Newbie
Posts: 9
Joined: Fri Jun 24, 2005 4:00 pm

Getting last page visited

Post by Sid3335 »

Hi:

How do i get the last page visited? for example a back button that returns to whatever page it came from.

in a script i have:
header("Location: index.php");

but i want it to direct back to the previous page not a predefined one.

Thanks.
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

$_SERVER['REFERER']

But you can't rely on it for anything serious, because it can be easily circumverted. After all, it depends on the browser to tell the server where it came from. If the browser can do that, so can you.
Sid3335
Forum Newbie
Posts: 9
Joined: Fri Jun 24, 2005 4:00 pm

Post by Sid3335 »

Thanks for the reply.

i was trying:
header($_SERVER['HTTP_REFERER']);

but it wasn't working, so i tried:
header("Location:".$_SERVER['HTTP_REFERER']);

and it works great.

just incase any one else is trying the same.

Thanks again.
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

Sid3335 wrote: header($_SERVER['HTTP_REFERER']);

but it wasn't working, so i tried:
header("Location:".$_SERVER['HTTP_REFERER']);
Yep, you have to tell the browser what to do with the referring URL. If ya don't, it won't know! :wink:

Remember, you can do lots of things with header() other than redirecting, lots more. Even more than that. Yea, that's better. :)
Post Reply