Page 1 of 1
Getting last page visited
Posted: Wed Dec 07, 2005 6:20 am
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.
Posted: Wed Dec 07, 2005 6:28 am
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.
Posted: Wed Dec 07, 2005 6:38 am
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.
Posted: Wed Dec 07, 2005 6:41 am
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!
Remember, you can do lots of things with
header() other than redirecting, lots more. Even more than that. Yea, that's better.
