107 posts
    Has been part of the Envato Community for over 2 years Sells items exclusively on Envato Market
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?

320 posts
    Has been part of the Envato Community for over 7 years Has collected 100+ items on Envato Market Located in United States
timmylogue says

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

http://www.htaccesstools.com/hotlink-protection/
5458 posts
    Has been part of the Envato Community for over 4 years Has referred 1+ members Located in Australia Has sold $1,000+ on Envato Market
+4 more
Australia says

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

211 posts
    Has referred 10+ members Has sold $10,000+ on Envato Market Has collected 1+ items on Envato Market Had an item featured on Envato Market
+3 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;
   }
}
275 posts
    Has been part of the Envato Community for over 3 years Has sold $1,000+ on Envato Market Has been a beta tester for an Envato feature Sells items exclusively on Envato Market
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?

211 posts
    Has referred 10+ members Has sold $10,000+ on Envato Market Has collected 1+ items on Envato Market Had an item featured on Envato Market
+3 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
627 posts
    Sells items exclusively on Envato Market Has been a beta tester for an Envato feature Has sold $10,000+ on Envato Market Has referred 1+ members
+1 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.

3917 posts After Effects Templates
    Has referred 500+ members Has sold $75,000+ on Envato Market and is now an Elite Author Has collected 100+ items on Envato Market Elite Author: Sold more than $75,000 on Envato Market
+8 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