107 posts
  • Exclusive Author
  • Has been a member for 2-3 years
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
  • Bought between 100 and 499 items
  • Has been a member for 7-8 years
  • United States
timmylogue says

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

http://www.htaccesstools.com/hotlink-protection/
5391 posts
  • Australia
  • Bought between 100 and 499 items
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Has been a member for 4-5 years
  • Interviewed on the Envato Notes blog
  • Referred between 1 and 9 users
  • Sold between 1 000 and 5 000 dollars
Australia says

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

211 posts
  • Canada
  • Sold between 10 000 and 50 000 dollars
  • Bought between 1 and 9 items
  • Referred between 10 and 49 users
  • Has been a member for 2-3 years
  • Exclusive Author
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;
   }
}
273 posts
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Has been a member for 3-4 years
  • Sold between 1 000 and 5 000 dollars
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
  • Canada
  • Sold between 10 000 and 50 000 dollars
  • Bought between 1 and 9 items
  • Referred between 10 and 49 users
  • Has been a member for 2-3 years
  • Exclusive Author
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
577 posts
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Has been a member for 2-3 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
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.

3902 posts After Effects Templates
  • Sold between 100 000 and 250 000 dollars
  • Exclusive Author
  • Elite Author
  • Referred between 500 and 999 users
  • Bought between 100 and 499 items
  • Envato Studio (Microlancer) Beta Tester
  • Beta Tester
  • Has been a member for 4-5 years
+4 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