Dragos Vana Dragos Vana - 2 months ago 9
PHP Question

php code to exclude google

i have a classifieds website. On this website i store in the db, each product page that a user visits for history purposes, so he can view the last products he visited.

The problem is that when googlebot and others enter my site, the db fills up with thousands of entrys because it sores the thousand product pages Google visit.

I tried various functions with

to try to find out is the current user is googlebot or not and if it is, not sore the page views in the db so that it's not spammed with unusefull results but none of them seem to work, as i get the Google ip's and recognize them in my db.

Do any of you know a good way in php to ensure google stays out?


You can use the following snippit which should detect the GoogleBot and not store to the database.

if (!strpos($_SERVER['HTTP_USER_AGENT'],"Googlebot")) {
     // log to database