PDA

View Full Version : Hot Linking remedy required


Radial
1-31-04, 12:45 PM
How can I stop others from direct linking to certain pages on my web site, is it possible to redirect them to the index page.

Example

If I had say 5 pages on my site and the most popular one was www.anyaddress.com/popular.htm
how can I stop others from directly accessing it, I would like to redirect them to the www.anyaddress.com instead, as I find many are linking directly to certain pages only.

Hope someone can advise me on this issue.

Thanks

Mirzabah
1-31-04, 07:26 PM
This is usually called "deep linking". To block it you each protected page to be a PHP page which checks the referrer. If the link isn't referred from your own site, then redirect the client to your home page. Something like this should do the trick:<?php

if (!preg_match ("|^http://(?:www\\\\.)?yourdomain\\\\.com|", $_SERVER['HTTP_REFERER']))
header ("Location: http://yourdomain.com") ;

?><html>
<!-- Your page -->
</html>Note that this code should only be used in protected pages. If you put it in your index.php page the browser would go into an infinite loop.

Mirzabah
1-31-04, 08:43 PM
I should also point out that the above code might hurt your rankings in search engines as it may block attempts to index your site. You could add checks to allow search engine bots through.

It help us come up with a better solution if you could explain why deep links are a problem for you.

Radial
2-2-04, 09:10 AM
I found this little script to work without compromising anything.

Place the script below within the <head> tags of the page your visitor enters.
Change index.html to the name of the page that you require your visitor to enter from

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var requiredfrom = "index.html"; // required prev. page
if (document.referrer.indexOf(requiredfrom) == -1) {
alert("You must come to this page from " + requiredfrom);
window.location=requiredfrom;
}
// End -->
</script>


This script was supplied free by Hypergurl
http://www.hypergurl.com