Jump to content

[SOLVED] Determine if its Google or Yahoo spidering my site, or is it actually visitors


woocha

Recommended Posts

Hey guys.

 

  I had a guys write this code for me a while back before I started to learn PHP.  The script is a stats tracker.  But, it must have some problems.  To see if it was working, I started using Google Analytics as well.  The Google stats tracker says I get 100 visits a day and the home brew version says I have 1000.  I am tending to believe the Google stats gizmo, but I want to fix the original one that was made for me.  SO here is my question:

 

Is it possible to determine that it is Google's or Yahoo's Spider checking out my site.

I'm thinking something like if(Google or Yahoo){don't count};

 

Is there anyway to do this?

 

Thanks fellas and Happy New Year !!

just record all the IPS of users in

then if its yahoos or googles (They are static) you can add to your count

 

I am affraid that might be a bit over my head.  Could you point in the right direction on how to do that?  I am more than willing to work on it and learn about.  Thank you

http://www.iplists.com/

 

Here is a listing with all the spiderbots and mediabots for the various sources. There are a LOT of them.

 

Looks like you would want to keep them each in a text file and then use a bit of code like so to see if the remote ip is in this list.

<?php
$visitors_ip=$_SERVER['REMOTE_ADDR']; // our guests IP
$botfiles=array('googlebots.txt','yahoobots.txt'); //array of bot files

foreach($botfiles as $file)
{
$botfile=file($file); //bot file
foreach($botfile as $v)
{
	$bots[]=trim($v);
}
}

if(in_array($visitors_ip,$bots))
{
// this is a google bot do what you want here
echo 'bot';
}
else
{
// this is not a google bot
echo 'not a bot';
}
?>

 

 

Grab all the bot files you want to compare to and add them to the array above. The script loops through and makes 1 big ass array with all the bot ips in there.

 

Hope this helps,

 

nate

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.