2

How can I know if google spiders or another spiders visit my page ?

<?php

if ("this is a spider") {
header('Location: index.php');
exit;
}

?>
Kara
  • 6,115
  • 16
  • 50
  • 57
faressoft
  • 19,053
  • 44
  • 104
  • 146

4 Answers4

5

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.

Community
  • 1
  • 1
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
1

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'].

Vincent Savard
  • 34,979
  • 10
  • 68
  • 73
1

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).

tanjir
  • 1,294
  • 13
  • 22
0

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.

GWW
  • 43,129
  • 11
  • 115
  • 108