FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

PHP script that checks referrer page?

 


ftv_flung
Basically, what I'm trying to do is only allow a user to enter a page if they have come from a certain page before.

For example, if they can't just go straight to the page, they have to go through another page (the referring page).


Thanks for any help,
ftv_flung
LukeakaDanish
The simple way is to use
Code:
$_SERVER['HTTP_REFERER']

BUT, seen as this string is set by the client it CAN'T be trusted - so if you use it for something where security is important...don't use it.

Alternatively you could use sessions (if both pages are on the same server).
ftv_flung
I have been using $_SERVER['HTTP_REFERER']

Users are already logged in, but I want them to go from Page 1 to Page 2 to Page 3 and not skip Page 2 - if that makes sense. So I've put the 'check what the referer is' code in Page 3.
LukeakaDanish
Ok! so whats the problem?
ftv_flung
It's not working!

Here's what I've got.


This is what's in Page 3 as a require.

Code:
<?php

$referer = $_SERVER['HTTP_REFERER'];

if ($referer == 'page2.php')
{
header('Location: page3.php');
}

else
{
header('Location: index.php');
}

?>


There's probably a better way of doing this Confused
LukeakaDanish
Code:
<?php

$referer = $_SERVER['HTTP_REFERER'];

if ($referer == 'page2.php')

First problem: Referer is a full URL (eg. http://www.google.com)
It could also be http://google.com - remember that the www prefix is optional in most cases
Code:

{
header('Location: page3.php');

Second problem. What happens here is the page changes to "page3.php" - once it gets there, it will test if "$referer" is page2.php...and it isn't! - its now page3.php. Either don't do anything here OR reverse the if bit (!= instead of ==)
Code:

}
else
{
header('Location: index.php');
}

?>

Rest is fine
ftv_flung
Thanks very much LukeakaDanish for your speedy help!

It's working Smile
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.