Jump to content

[SOLVED] track spiders on my site?


marksie1988

Recommended Posts

So would something like the following work? and would this be able to post the information for all users to see or just the bot? or would i need to write the information into a database and then display this information?

 


<?php
function agent($bot) {
$useragent = $_SERVER['HTTP_USER_AGENT'];
return strstr($useragent,$bot);
}

if(agent("WISENutbot") !== FALSE) {
echo "Looksmart Bot";
}
else if(agent("Googlebot") !== FALSE) {
echo "Google Bot";
}
else {
echo "";
}
?>

it's the way your session handler works. many forums and other CMS's use the database to store sessions, so they can store additional info such as the user agent, IP, etc.

 

This way, all you need is a simple query to the sessions table and you're away.

 

see http://uk.php.net/session_set_save_handler

 

there are other ways of doing it, made easier if you have a common include file for every request (such as a front controller). simply store the IP/Agent/Timestamp, etc followed by a cleanup of records that are older than a certain period, and you're done. Just query the table when you need the info.

The reason why I personally use sessions is just keeping all info together as there are many other uses, too.

http://www.ronaldsteelman.com  the first post on there. I wrote it up real quick like for ya.  Has sample code and a site with a list of ALL the bots that exist.  Pick your favorite ones and go with it.

 

tried this but nothing gets written to the database i did it the same as in your tutorial aswell

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.