<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>tech stuff &#187; detect</title>
	<atom:link href="http://codytaylor.org/tag/detect/feed" rel="self" type="application/rss+xml" />
	<link>http://codytaylor.org</link>
	<description>From Cody Taylor.</description>
	<lastBuildDate>Sun, 30 Oct 2011 04:15:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Detect Bots By Parsing The User Agent With PHP</title>
		<link>http://codytaylor.org/2009/06/detect-bots-by-parsing-the-user-agent-with-php.html</link>
		<comments>http://codytaylor.org/2009/06/detect-bots-by-parsing-the-user-agent-with-php.html#comments</comments>
		<pubDate>Sun, 14 Jun 2009 05:51:50 +0000</pubDate>
		<dc:creator>Cody Taylor</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[bot]]></category>
		<category><![CDATA[detect]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[user agent]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://codytaylor.org/?p=14119</guid>
		<description><![CDATA[Because I've been starting to keep a closer eye on my traffic I've been...]]></description>
			<content:encoded><![CDATA[<p>Because I&#8217;ve been starting to keep a closer eye on my traffic I&#8217;ve been logging everything to my databases. When writing reports for this information I noticed that there was huge amounts of traffic from bots. Yahoo, Google, MSN and many others have been hammering my sites quite a lot lately. Since I&#8217;m writing my reports in PHP I needed a quick little function to identify whether the visitor was real traffic or some machine scraping my site. I couldn&#8217;t find one after a few quick Google queries but the solution was trivial so I wrote my own. Hopefully this will save someone a few minutes. The function is as simple as possible and it seems to be working so far. I&#8217;ve been watching it for awhile and it hasn&#8217;t missed any yet. I&#8217;m assuming that it&#8217;s not going to catch everything but it would be nice to get most. Any bot user agent string suggestions would be helpful.</p>
<p><pre><code>
//returns 1 if the user agent is a bot
function is_bot($user_agent)
{
&nbsp;&nbsp;//if no user agent is supplied then assume it&#039;s a bot
&nbsp;&nbsp;if($user_agent == &quot;&quot;)
&nbsp;&nbsp;&nbsp;&nbsp;return 1;

&nbsp;&nbsp;//array of bot strings to check for
&nbsp;&nbsp;$bot_strings = Array(&nbsp;&nbsp;&quot;google&quot;,&nbsp;&nbsp;&nbsp;&nbsp; &quot;bot&quot;,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;yahoo&quot;,&nbsp;&nbsp;&nbsp;&nbsp; &quot;spider&quot;,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;archiver&quot;,&nbsp;&nbsp; &quot;curl&quot;,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;python&quot;,&nbsp;&nbsp;&nbsp;&nbsp; &quot;nambu&quot;,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;twitt&quot;,&nbsp;&nbsp;&nbsp;&nbsp; &quot;perl&quot;,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;sphere&quot;,&nbsp;&nbsp;&nbsp;&nbsp; &quot;PEAR&quot;,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;java&quot;,&nbsp;&nbsp;&nbsp;&nbsp; &quot;wordpress&quot;,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;radian&quot;,&nbsp;&nbsp;&nbsp;&nbsp; &quot;crawl&quot;,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;yandex&quot;,&nbsp;&nbsp;&nbsp;&nbsp; &quot;eventbox&quot;,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;monitor&quot;,&nbsp;&nbsp; &quot;mechanize&quot;,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;facebookexternal&quot;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);
&nbsp;&nbsp;foreach($bot_strings as $bot)
&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;if(strpos($user_agent,$bot) !== false)
&nbsp;&nbsp;&nbsp;&nbsp;{ return 1; }
&nbsp;&nbsp;}
&nbsp;&nbsp;
&nbsp;&nbsp;return 0;
}
</code></pre></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcodytaylor.org%2F2009%2F06%2Fdetect-bots-by-parsing-the-user-agent-with-php.html&amp;linkname=Detect%20Bots%20By%20Parsing%20The%20User%20Agent%20With%20PHP"><img src="http://codytaylor.org/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://codytaylor.org/2009/06/detect-bots-by-parsing-the-user-agent-with-php.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

