Why are you doing this in JavaScript, and asking on a PHP message board?
To do this in PHP you'd just do this:
<?php
$from = $HTTP_SERVER_VARS["HTTP_REFERER"];
$valid_from = array("somepage", "someotherpage");
$valid = false;
for (i = 0; i <= length($valid_from); $i++) {
if ($from == $valid_from[$i]) {
$valid = true;
}
}
if (!$valid) {
header("Location: $from"); // kick them back without telling them why
}
//do rest of page
?>
You can do the translating of that to JavaScript if thats the way you want to go, but remember JavaScript is client side and if someone has there JavaScript turned off in there browser then the will see this page no matter where they came from.