ColdFusion Session Management And Spiders / Bots

<!---
	Check to see if we have a standard user or a spider. We
	can test the user agent for commonly known spider bots.
	First, let's get the user agent in lower case so that we
	can do faster non-case-sensitive testing.
--->
<cfset REQUEST.UserAgent = LCase( CGI.http_user_agent ) />
 
 
<!---
	Now, let's check for a spider and set the session timeout
	accordingly (we will single out the session timeout so that
	we can define the application in a single place).
 
	In addition, we are adding a special diagnostic test
	so that the user can test the short session (since it's
	more complicated to spoof a spider).
--->
<cfif (
	<!--- Run diagnostic test. --->
	StructKeyExists( URL, "TestShortSession" ) OR
 
	<!--- Test user agents. --->
	(NOT Len( REQUEST.UserAgent )) OR
	REFind( "bot\b", REQUEST.UserAgent ) OR
	Find( "crawl", REQUEST.UserAgent ) OR
	REFind( "\brss", REQUEST.UserAgent ) OR
	Find( "feed", REQUEST.UserAgent ) OR
	Find( "news", REQUEST.UserAgent ) OR
	Find( "blog", REQUEST.UserAgent ) OR
	Find( "reader", REQUEST.UserAgent ) OR
	Find( "syndication", REQUEST.UserAgent ) OR
	Find( "coldfusion", REQUEST.UserAgent ) OR
	Find( "slurp", REQUEST.UserAgent ) OR
	Find( "google", REQUEST.UserAgent ) OR
	Find( "zyborg", REQUEST.UserAgent ) OR
	Find( "emonitor", REQUEST.UserAgent ) OR
	Find( "jeeves", REQUEST.UserAgent )
	)>
 
	<!---
		This is a spider, so set a really small timeout. In
		this case, we are going to go with 2 seconds.
	--->
	<cfset REQUEST.SessionTimeout = CreateTimeSpan( 0, 0, 0, 2 ) />
 
<cfelse>
 
	<!---
		This is a standard web user, so allocate a standard
		session timeout of 20 minutes.
	--->
	<cfset REQUEST.SessionTimeout = CreateTimeSpan( 0, 0, 20, 0 ) />
 
</cfif>
 
 
<!---
	ASSERT: At this point, no matter what type of user is
	visiting the site, we know what session timeout to supply.
--->
 
 
<!--- Define the application with given session timeout. --->
<cfapplication
	name="SessionTesting"
	applicationtimeout="#CreateTimeSpan( 0, 1, 0, 0 )#"
	sessionmanagement="true"
	sessiontimeout="#REQUEST.SessionTimeout#"
	/>
 
 
<!--- Set page request settings. --->
<cfsetting
	showdebugoutput="false"
	requesttimeout="20"
	/>

For Cut-and-Paste