You can probably use the $_SERVER superglobal, specifically with 'HTTP_REFERER'.
//This variable will be the last page address
$lastPage = $_SERVER['HTTP_REFERER'];
//Use a condition to check the last page against the allowed page
if($lastPage != 'http://example.com/page.php') {
//False
}
You can probably easily break down the previous address so that you can have only the page name (just 'page.php').
Something like this:
<?
//Variable containing last page address
$lastPage = $_SERVER['HTTP_REFERER'];
//Split, or 'explode', the address into pieces every time there is a slash (/)
$ad_array = explode('/',$lastPage);
//Reverse the array so that the first value is whatever is past the last slash
$ad_array = array_reverse($ad_array);
//This variable SHOULD contain the page name of the last address (page.php, etc)
$pageName = $ad_array[0];
//Condition to check the last page name against what you want it to be
if($pageName != 'page.php') {
//False
}
?>
I didn't test this, it's just a guess, but I'm sure it will work.
You can experiment a bit more with that. More information on $_SERVER here:
http://us.php.net/reserved.variables.ser ver