107 posts
  • 3 Years of Membership
  • Exclusive Author
mailmilisku
says

Hi there,
I knew we can use htaccess to block visitor from specific country or IP address. Is it possible to block specific site to prevent visiting my site?

332 posts
  • 8 Years of Membership
  • Collector Level 4
  • United States
timmylogue
says

Don’t know what you mean…. Do you mean hotlinking?

http://www.htaccesstools.com/hotlink-protection/
5492 posts
  • 5 Years of Membership
  • Affiliate Level 1
  • Australia
  • Author Level 3
+5 more
Australia
says

you can set disallow via robots.txt, not sure you can block a website from visting your website …

262 posts
  • Trendsetter
  • Exclusive Author
  • Author Level 6
  • Affiliate Level 3
+4 more
KBRmedia
says

I am not sure what you mean by “block specific site to prevent visiting my site”, but if you want to block users who are refered by a site, you can use HTTP_REFERER but it might not always work. Here is a sample code that you can use. Make sure to put on top of everything else.

if(isset($_SERVER['HTTP_REFERER'])) {
   $url=parse_url($_SERVER['HTTP_REFERER']);
  if($url["host"]=="google.com" || $url["host"]=="www.google.com") {
          //If you want to block users from google.com then do something here
         // You can redirect or just show a blank page
    exit;
   }
}
293 posts
  • 4 Years of Membership
  • Author Level 3
  • Beta Tester
  • Exclusive Author
candeed
says

I am not sure what you mean by “block specific site to prevent visiting my site”, but if you want to block users who are refered by a site, you can use HTTP_REFERER but it might not always work. Here is a sample code that you can use. Make sure to put on top of everything else.
if(isset($_SERVER['HTTP_REFERER'])) {
   $url=parse_url($_SERVER['HTTP_REFERER']);
  if($url["host"]=="google.com" || $url["host"]=="www.google.com") {
          //If you want to block users from google.com then do something here
         // You can redirect or just show a blank page
    exit;
   }
}

Interesting.. So in that code example referred visitors from google.com will be redirected to blank page right?

What about visitors referred from subdomains such as ‘subdomain.google.com’ ? Will they get redirected too?

262 posts
  • Trendsetter
  • Exclusive Author
  • Author Level 6
  • Affiliate Level 3
+4 more
KBRmedia
says

Currently, it doesn’t redirect to any pages. It just stops executing the script hence showing just a blank page. But if you want to redirect it, you can just add header("Location: http://YOURSITE/SOMEPAGE"); right before exit.

For other subdomains you would have to add them to the code e.g. || $url["host"]=="subdomain.google.com" or you could set up an array of your blocked sites and then simply match the domain/subdomain to the list using preg_match or something.

abhimanyusharma003
abhimanyusharma003 Recent Posts Threads Started
945 posts
  • Blog Interview
  • Trendsetter
  • Exclusive Author
  • Beta Tester
+3 more
abhimanyusharma003
says

I think you need to get the link via HTTP_REFERER first.
Or if you want you can check my profile will try to customize the ‘bad blocker’ script for you just mail me.

4151 posts After Effects Templates
  • Author Level 8
  • Elite Author
  • Top Monthly Author
  • Weekly Top Seller
+12 more
miseld
says

If you are using Cpanel, go to “IP Deny Manager”

This feature will allow you to block a range of IP addresses to prevent them from accessing your site. You can also enter a fully qualified domain name, and the IP Deny Manager will attempt to resolve it to an IP address for you.

by
by
by
by
by
by