-2

I am planning to have 2 versions(A/B) of a page. If the visit comes from the Google Bot visit, the response should be the A version or If the visit comes from the Bing Bot visit, the response should be a the B version. How do I know if the visit is from the Google Bot or Bing Bot in PHP?

Thanks.

rkt
  • 1,171
  • 2
  • 9
  • 18
  • easy enough to do - but why? The bots should see what the humans see - that's the point of them. –  Apr 25 '12 at 23:33
  • the 2 pages differ slightly in terms of keywords,title,meta,desc .. they aren't exactly the same – rkt Apr 25 '12 at 23:35
  • and does google care about meta keywords -nope. The SEO scammes ruined that. –  Apr 25 '12 at 23:37
  • 1
    Is there some `real` reason for doing this? You should not try to give bots some specially crafted `bots only` content. It may have worked years ago but not today, some sites managed to get banned for a while from search engines _(i've heard most banned by google, dont know about others)_ because of attempts to change content if visitor is bot... – Sampo Sarrala - codidact.org Apr 25 '12 at 23:45
  • @Sampo Reminds me of the old cgi scripts from the early 2000's that would do search engine cloaking. You are correct in that SE's will penalize you if you show radically different content for a bot. – drew010 Apr 26 '12 at 00:01

1 Answers1

3

First figure out what the User Agent string is for the bots by going here: http://www.robotstxt.org/db.html

Next check the user agent using PHP:

if (strpos($_SERVER['HTTP_USER_AGENT'],"Googlebot")){
    //Show Page A 
}else if(strpos($_SERVER['HTTP_USER_AGENT'],"MSNBOT")){
    //Show Page B
}

But why? The bots are supposed to see what people see so they can index the site on the search engine.

Tim Withers
  • 12,072
  • 5
  • 43
  • 67
  • probably *another* misguided SEO attempt - sad, its real content that matters. –  Apr 25 '12 at 23:38
  • My access logs show this user agent for bing: `Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)` so he may need to check that instead of MSNBOT. – drew010 Apr 25 '12 at 23:40
  • @drew010 I thought it wasn't right, but I searched that page I listed and couldn't find 'bingbot', but I found MSNBot. I checked google and bingbot was again listed as MSNbot, so I put that in the code. So you are probably right on that. – Tim Withers Apr 25 '12 at 23:43
  • If i remember correctly there's been `bingbot` hitting our server. – Sampo Sarrala - codidact.org Apr 25 '12 at 23:58
  • @TimWithers I just double checked my log files and I don't have any MSNBOT agents at this time, but I do see the bing bots are coming from host names like `msnbot-65-52-108-12.search.msn.com` It could be that they still use MSNBot and I just don't have any records. For the asker's sake I guess he could check both and assume bing if he wanted to be sure. 2 more minutes til I can upvote again... – drew010 Apr 25 '12 at 23:58
  • Checked logs and there was `Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)` coming from `msnbot-207-46-13-143.search.msn.com`. Bingbot.htm says that `Bing operates three crawlers today: bingbot, adidxbot, msnbot`. It also says that `Bingbot will take over MSNbot`. – Sampo Sarrala - codidact.org Apr 26 '12 at 00:05