PDA

View Full Version : .htaccess scripty


BobbX
12-28-2006, 04:09 PM
Anyone know of a way of redirecting a user so that they can't go to a page directly without coming from the index.html page? I've seen this script online somewhere now I can't find it.

dkinzer
12-28-2006, 11:39 PM
You might be able to use the HTTP referrer to allow/disallow access: $_SERVER['HTTP_REFERER']. A link from your own site to a page would include your URL while a directly typed URL or link from another site would not.

You can experiment with these scripts to see the effect:

q1.php:
<?php
echo "HTTP_REFERER=[" . $_SERVER['HTTP_REFERER'] . ']<br>';
?>

q2.php:
<?php
echo '<a href="q1.php">click here</a></br>' . "\n";
?>
Upload both of them to some directory on your site an observe the results.

felgall
12-29-2006, 12:41 PM
Of course if you use that method you need to take into account what percentage of your visitors have disabled the referrer field to protect their privacy (and which therefore don't have anything useful in that field to tell you where they came from).

The better way would be to use a session where you set a session variable on the home page and build a redirect into the top of all of the other pages to go to the home page if that variable isn't set.