there is a more complex solution to this problem.
simply use sessions, php has access to the item $SERVER['HTTP_REFERRER'] which isn't alway set... so make your own manual variable you update that lives in $SESSION
put something in the users session at the end of every page
page_x.php
<?php #START OF FILE
# stuff
# stuff
# END OF FILE
$_SESSION['came_from'] = $_SERVER['PHP_SELF'];
?>
and the other pages check to see where they came from
page_y.php
<?php #START OF FILE
# only accepts ppl that came from page_x
if ( !isset($_SESSION['came_from']) || $_SESSION['came_from']!='page_x.php' ) {
# redirect user
}
# stuff
# stuff
# END OF FILE
$_SESSION['came_from'] = $_SERVER['PHP_SELF'];
?>