Page 1 of 1

Accessing Page ONLY after visiting Previous Page ?

Posted: Wed Feb 01, 2006 8:35 am
by hbnmgr
Have PHP v4.3 installed on Server.

Need to make sure browser visiting a certain page,
came from another page or at least from the same
domain / server.

To prevent browser from accessing that certain page
without first visiting the previous page and from same
domain / server. Pervious page is coming off of PayPal
and is a ThankYou page.

Any suggestions as to what best to use???
SESSION ; REFERER ; SERVER ; etc. ???
Can't find code in two books I have.

Thanks!
SRR

Posted: Wed Feb 01, 2006 8:51 am
by Roja
http_referer is the closest, but it isnt entirely reliable.

Posted: Wed Feb 01, 2006 9:10 am
by Jenk
If you are trying to secure a multiple stage form submission for example, then $_SESSION will help.

If you are just limiting access based on referal, then $_SERVER['HTTP_REFERER'] is a viable, but by no means a fool proof method.

To use the method I described with session:
page1.php:

Code: Select all

<?php
session_start();

$_SESSION['page1visited'] = TRUE;

?>
page2.php:

Code: Select all

<?php
session_start();

if ((isset($_SESSION['page1visited'])) && ($_SESSION['page1visted'] == TRUE)) {
    //display page..
} else {
    die('You must visit page1.php before gaining access to page2.php!');
}

?>
HTH :)