FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free 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
Related topics
Phoenix free PHP scripts
error in my PHP script
how can i make a php script for enter username and password?
Inserting data to MYSQL with a PHP script
Running a "Hello World" php script
Logging systeem php script
Preventing bad PHP script calls
Need php script 50 frih$ if you do
Connected to another part of a php script.
Browser close run a php script.
PHP Script Needed for 250 frih$
Uploading an Image using PHP script - RESOLVED
Private message system "delete selected."
PHP script execution time
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

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