Reputation: 19651
How can I know if google spiders or another spiders visit my page ?
<?php
if ("this is a spider") {
header('Location: index.php');
exit;
}
?>
Upvotes: 2
Views: 2508
Reputation: 1334
You can look for the value of global variable: $_SERVER['HTTP_USER_AGENT'] . For google spider, the value will look like "Googlebot*"
PHP's get_browser function is also useful (check if the returned browser type is known or not- if not then most likely spider or crawler).
Upvotes: 1
Reputation: 449435
You can use the USER_AGENT
header to recognize most search engine crawlers as described in this question.
However, be warned that what you seem to be trying to do - presenting different content to crawlers than human visitors - is a technique also known as "cloaking" and not well received at all by search engines.
As far as I know, with Google, this can lead to heavy penalties, up to your site vanishing from the index completely.
I would let this be, and employ legit SEO optimization instead.
Upvotes: 5
Reputation: 44093
While the user agent is a decent sign that it's the googlebot, a better process would be to use what's outlined here (after checking the user agent) because it's quite easy to fake a user agent. The functions gethostbyaddr and gethostbyname would be good for this.
Upvotes: 0
Reputation: 35927
You have to check the user agent. You can check those pages for more information :
http://fr.wikipedia.org/wiki/User-Agent#Robots
http://www.user-agents.org/
Then, you just have to parse the variable $_SERVER['HTTP_USER_AGENT'].
Upvotes: 1