Industry guru Dave Taylor answers free tech support questions about a wide variety of business and technical topics, including blogging, Google AdSense, MySpace, Sony PSP, Apple iPod, Mp3 players, management, Linux, SEO, Mac OS X, Facebook, Twitter, LinkedIn and Microsoft Windows.

Can I selectively block people from visiting my Web site?

Dave, we've got a problem. I help run a Web site and we're finding that there's one troll out there (yes, I read your article on trolls a few days ago!) who keeps showing up and posting inflammatory comments, really ruining the guest book for everyone else. Is there a way to selective block one person without just tossing the whole guestbook out?


Dave's Answer:

Sorry to hear about your problems, but it doesn't entirely surprise me. For all that we as a society talk about free speech and the right to disagree, it only seems to extend in one direction: "You need to listen to me and you can't shut me up."

For you to be able to accomplish what you want -- a tactic I endorse, by the way, and do not see as censorship in other than the most general way -- you're going to find that the solution varies based on what kind of Web server you have running.

A good first step, therefore, is to ask your Web hosting provider what kind of server they run. A good answer is Apache, because it's flexible and easily tweaked to accomplish this task. If you have something else, like Microsoft's Internet Information Server (aka "IIS"), you'll need their help setting this up, because the solution I'm offering is Apache-specific.

If you are running Apache, then go into the directory that contains the guest book (or that contains the CGI script itself, for that matter) and, in a file called .htaccess, add the following:

<Directory /what/ever>
Order Allow,Deny
Allow from all
Deny from 10.1.2.3
</Directory>

Switch "/what/ever" to match the directory name. That should do it. If that doesn't work, you can also drop this block into your httpd.conf file, if you're comfortable editing that file.

Once it's installed, you'll want to change the 10.1.2.3 to the IP address of the offending party (look in your log files for that information).

Hope this helps you solve the problem. Good luck.

My thanks to Omar W. Hannet for his help with this entry. Please pop over to the Apache Web site for more details on mod_access



Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Simpy.

Subscribe!

Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader.

Comments

Dave, while your solution works for a fairly large number of cases, I see at least two flaws: it blocks EVERYONE from the entered IP address, and doesn't account for "shifting" / non-permanent IP users. (Apologies, all of my alternative solutions fall back upon inspecting user-entered identification fields, which aren't consistently supported by guestbook packages...)

ttfn - Mike / Pax ... Kihe

Posted by: Mike C. Baker at February 11, 2005 6:17 PM

I agree. Do you have a suggestion as how you could tweak Apache to include those cases?

Posted by: Dave Taylor at February 12, 2005 2:56 AM

You can use cookies to track the troll and deny access to your pages.

This can be a little tricky, because you don't know in advance the new IP of the troll. One solution is to seek for words only the troll uses, and atach a special cookie to identify the computer the troll is using.

Implementetion in PHP is probably the easiest way to do it.

Posted by: Julio Poisot at February 22, 2005 5:31 PM

You can use cookies to track the troll and deny access to your pages.

This can be a little tricky, because you don't know in advance the new IP of the troll. One solution is to seek for words only the troll uses, and atach a special cookie to identify the computer the troll is using.

Implementing it in PHP is probably the easiest way to do it.

Posted by: Julio Poisot at February 22, 2005 5:31 PM

get your cgi to look up a list of banned words!

Posted by: kjteoh at May 15, 2005 7:53 AM

i can not on block her

Posted by: B at August 11, 2005 2:29 PM

I use Typepad to blog, and I'd like to block specific users from accessing my blog. Since i"m not hosting on Apache, do you know of any way that I could block people from visiting? Thanks!

Posted by: A Hsu at December 12, 2005 4:29 PM

I'm afraid you can't do that with Typepad. You can block specific people from adding comments (if you know their IP addresses) but you can't block people from *reading* your site. Sorry!

Posted by: Dave Taylor at December 12, 2005 4:41 PM

Hi Dave,

My problem is slightly different. When I look through my site's log, I see that I'm getting hundreds of hits from spam addresses in my "links from external addresses" list. I'm not sure whether the point of the spam hits is just to have webmasters check out their referrers and in that way generate traffic to their website, or whether (more likely) the idea is to have their sites show up in my log, in the hopes that the log is linked to the main site, so they can increase their Google rankings. In any case, I'm getting tired of manually listing all the offending URLs in my htaccess file.

My question, therefore, is: does anyone publish a list of spam URLs that webmasters can add to their htaccess files? Or, even better, is there some service such as AdBlock that tracks the spammers and that you can somehow route your htaccess files to check?

Any thoughts would be most welcome!
Thanks,
Martin

BTW, here's my current .htaccess file

Order Allow,Deny
Allow from All
Deny from web4u.gb.com
Deny from uaeecommerce.com
Deny from 8gold.com
Deny from fidelityfunding.net
Deny from houseofsevengables.com
Deny from crepesuzette.com
Deny from popwow.com
Deny from condodream.com
Deny from canadianlables.net
Deny from 911easymoney.com
Deny from lucky7.to
Deny from 20six.co.uk
Deny from www.whymarketing.info
Deny from free-online-dating.18.to
Deny from byondspeed.com
Deny from brasilbeachhouses.com
Deny from muscle-food.com
Deny from shayanashop.com
Deny from tinnisexshop.com
Deny from tinni-lingerie.com
Deny from happiezz.com
Deny from miltontwins.iblogs.com
Deny from freevideos.iblogs.com
Deny from ebook2buy.com
Deny from livedatematch.com
Deny from d-daystore.com
Deny from talented-doctor.com
Deny from just-pills.com
Deny from metasart.com
Deny from dianejones.com
Deny from birchfieldharriers.org
Deny from pills-sale.com
Deny from furnituredeals.org
Deny from mobilewifi.com
Deny from 3brothersonline.com
Deny from casino-run.com
Deny from posterstm.com
Deny from casino-denotation.com
Deny from osagedata.com
Deny from poker-scan.com
Deny from villarentalbali.com
Deny from seat208.com

Posted by: Kamusi Project at February 4, 2006 10:03 AM

Dave,
We have a guestbook people from all over the world come, ask for prayer, leve messages and all these are more then welcomed. But now we have someone leving ads. They always start with a link address. I do not know a lot about computers and do not know how to block this from happening on our guestbook. This morning we had 40 and before the day is over, it could reach 100 or more. We have to go in and delete them. We would like to block them so they can never come on. Don

Posted by: Don at February 7, 2006 8:46 AM

Martin and Don, I'm afraid to say that at some level the spammers win this war because you'd have a prohibitively long list of domains to block and that still wouldn't work because spam tools can "spoof" or pretend to be from other domains entirely. :-(

Further, open tools like guest books are just an invitation for trouble, I'm sorry to say, so unless you can change your guestbook system to leave entries as "unpublished" until you manually approve them, you're probably better off disabling the guest book entirely.

Both of these answers are terrible and I greatly miss the free and open nature of the Internet as it was years ago and every entry to a guest book was a voice from the great unknown and highly anticipated. But as far as I can see, there's no going back. :-(

Posted by: Dave Taylor at February 7, 2006 1:52 PM

// Block IP address script- By JavaScriptKit.com (http://www.javascriptkit.com)
// For this and over 400+ free scripts, visit JavaScript Kit- http://www.javascriptkit.com/
// This notice must stay intact for use.

//Enter list of banned ips, each separated with a comma:
var bannedips=["23.23.23.23", "11.11.11.11"]

var ip = ''

var handleips=bannedips.join("|")
handleips=new RegExp(handleips, "i")

if (ip.search(handleips)!=-1){
alert("Your IP has been banned from this site. Redirecting...")
window.location.replace("http://www.google.com")
}

You will need to change the 23.23 and 11.11 of course. This works great for the most part, but if they have a changing ip address you will have to block a lot more.

Posted by: Faith at May 11, 2006 7:43 AM

I recently Googled an old techie friend and discovered she now has a company, and she made her email address at her company's website public. So I sent her an email, and got no reply. A few days later, I found that when I tried to go to her website my browser said it didn't exist ("cannot find" etc). Before assuming the worst; i.e. that she selectively blocked me-- I was wondering, IS this what my browser would say in such a situation? Or would it instead be something like "access denied"?
Her site has been in this condition for a couple of days now, so I don't know what's going on. I don't want to come across like an obsessive by going to the library and trying to contact her on a machine there. But I don't want to prematurely give up trying to reach her, either. She is an open-source guru, so she's probably quite capable of doing very sophisticated blocks. That being the case, is it technically possible for her block to look the way I described above?

Posted by: van casey at December 1, 2006 11:32 PM

I just read the posting from Van Casey on 12/1/06. I have a similar issue in that a site for the Club managers Association of America (www.cmaa.org)does not open when I click on it. I notified their techies and they said I needed to relax my security on my computer. I did that but to no avail. When I called a friend, he was able to access their site. So my question is WHAT TO DO? I cannot believe that a national organization would just seleectively block someone from accessing their site. Please help. Much appreciated.

Posted by: Hondo Hughes at December 5, 2006 8:32 AM

can i block a whole bunch of IPs by using the *? for example

<Directory /what/ever>
Order Allow,Deny
Allow from all
Deny from 10.1.2.*
</Directory>

Posted by: iced nyior at April 5, 2007 3:41 AM

I have a lot to say, but ...
Starbucks coffee cup I have a lot to say, and questions of my own for that matter, but most of all I'd like to say thank you for all your efforts on this Web site by buying you a chai!

I do have a comment, now that you mention it!









Remember personal info?


Please note that I will never send you any unsolicited commercial email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.









Search
Find just the answers you seek from among our 1700+ free tech support articles by using our Lijit search engine.


Help!





Subscribe to
Ask Dave Taylor!

Add to Google Reader
Add to My Yahoo!
Subscribe in NewsGator Online

RDF   XML

Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.


Recent Entries
Join the List!
Join my author info mailing list, where you'll learn about my upcoming books, speaking gigs, and more!


Book Links
© 2002 - 2008 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site.

[whiteboard marker tray]