This tutorial will show you how you can implement a system into your web site that will notify you when a search engine robot is crawling your site. The first thing you do is to create a variable called "stringToSearch" that contains the visitor (or robot) browser system (or better known as USER_AGENT).

<cfset stringTosearch = cgi.USER_AGENT>

Next, we will look to see if it it a real browser or not:

<cfif (findnocase(
"MSIE",stringToSearch) EQ 0) AND
       (findnocase(
"Gecko",stringToSearch) EQ 0) AND
       (findnocase(
"Opera",stringToSearch) EQ 0) AND
       (findnocase(
"Konqueror",stringToSearch) EQ 0) AND
       (findnocase(
"Safari",stringToSearch) EQ 0) AND
       (findnocase(
"Netscape",stringToSearch) EQ 0)>

     <!--- THE VISITOR IS NOT USING A BROWSER, SEND AN EMAIL ALERTING ME ITS A ROBOT CRAWLING MY SITE --->

     <cfmail to=
"bots@yourdomain.com"
                from=
"bot#cgi.REMOTE_ADDR#@yourdomain.com"
                subject=
"Spider Bot Alert"
                type=
"HTML"
                server=
"mail.yourdomain.com">

             <font face="verdana" size="2">
               <p><a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=#cgi.REMOTE_ADDR#">#cgi.REMOTE_ADDR#</a></p>
               <p>#cgi.HTTP_USER_AGENT#</p>
               <p><a href="#cgi.HTTP_REFERER#">#cgi.HTTP_REFERER#</a></p>
             </font>
     </cfmail>
</cfif>

About This Tutorial
Author: Jim Summer
Skill Level: Beginner 
 
 
 
Platforms Tested: CF5
Total Views: 110,265
Submission Date: April 14, 2004
Last Update Date: June 05, 2009
All Tutorials By This Autor: 1
Discuss This Tutorial
  • Sorry for the bad code Z. Yes I want dozens of emails... that is the reason for the cfabort. Once I identify bothersome bots they are in essence blocked by the identification of the IP and the cfabort. Thank you, Jim S. http://tentonweb.com/ Jacksonville, Florida USA

  • Why do people submit bad code here without thinking for just one minute how best to write it? (Same concept applies to the comment with 50 abort tags.) Why waste processing time generating pretty html emails for something so simple that can go in text? Anyway, careful where you put such code. When a bot grabs dozens of pages on your site in a few minutes, do you really want dozens of emails???

  • This blocks bad bots by name and IP's as you find them - sends me an email if not a bad bot. Used as an include file on whatever pages you want - tells you in the email what page was hit. At some point I will store all of these bad bot IP's in a db and loop through that - but... not yet :) ############ Your IP has been added - #ip# Your IP has been added - #ip# Your IP has been added - #ip# Your IP has been added - #ip# Your IP has been added - #ip# Your IP has been added - #ip# Your IP has been added - #ip# Your IP has been added - #ip# Your IP has been added - #ip# Your IP has been added - #ip# Your IP has been added - #ip# Your IP has been added - #ip# Your IP has been added - #ip# Your IP has been added - #ip# Your IP has been added - #ip# Your IP has been added - #ip# Your IP has been added - #ip# Your IP has been added - #ip#

    IP: #ip#
    PAGE: #thispage#
    REFERRER: #strRef#
    USER AGENT: #agent#

    ############ Hope this helps... Thank you, Jim S. http://tentonweb.com/ Jacksonville, Florida USA

  • I just checked my code and all instances referring to this are written as such: #cgi.HTTP_REFERER# - I get emails from this every day so I am sure it is working properly. I will post another way to do this that I am using on another site - that blocks bothersome bots as I encounter them... that post is next. Thank you, Jim S. http://tentonweb.com/ Jacksonville, Florida USA

  • Http_referer generates error when the site is searched using bot or search engines. How to get rid of that error?

  • Hey folks this stuff is very inportant to keep track of your visibility? Try a search at (any) search engine for the phrases: Jacksonville Web Design or Resume Cold Fusion or Resume ASP just to see for yourself... Resume ASP I am like #1 out of over 5 million returns at Google!!! Whoa... Thanks a lot and once again thanks to Pablo for this great site! I work with him now (thanks for the tip) he is quite a character in addition to being a great Cold Fusion programmer! Jim Summer http://tentonweb.com/

Advertisement

Sponsored By...
Mobile App Development (IOS, Android, Cordova, Phonegap, Objective-C, Java) - Austin, Texas Mobile Apps - Touch512, LLC.