Click to See Complete Forum and Search --> : Reach page only by clicking on link
konithomimo
02-21-2005, 12:44 PM
How can I make it so that people can only reach a page on my site by only clicking on the link on my website, not by entering the URL for that page. I want it so that if they enter the URL for the page that they are redirected to my main page, but if they click on the link then tehy are not redirected. I know that you can use META tags to redirect, but they are really slow in Mozilla Firefox, and they always redirect, even when you click on the link for that page. :( PLEASE HELP ME!!!
phpnovice
02-21-2005, 12:50 PM
Three are only two ways to accomplish this -- JavaScript (via cookies) or server-side code (via sessions). HTML alone cannot do this.
Daniel T
02-21-2005, 12:52 PM
Do you have PHP available to you? If so, you could do this:<?php
if(!preg_match("/^http\:\/\/(www\.)yoursite\.com/", $_SERVER['HTTP_REFERER']) header("Location: index.htm");
?>Of course, change the domain name "yoursite.com" to your domain name.
Otherwise, I think there is a JavaScript way, but I don't know much JavaScript.
EDIT
Darn forum screwed up my code... I'll attatch it.
Daniel T
02-21-2005, 03:45 PM
phpnovice
02-21-2005, 04:46 PM
Originally posted by Daniel T
<?php
if(!preg_match("/^http\:\/\/(www\.)yoursite\.com/", $_SERVER['HTTP_REFERER']) header("Location: index.htm");
?>
The JavaScript equivalent of that code is as follows:
if(!/^http\:\/\/(www\.)yoursite\.com/.test(document.referrer)) {
top.location.href = "index.htm";
}
However, both the PHP code provided and this JavaScript code will fail if the referring site is configured to not send this header.