so I had built an age verification page that blocks crawlers from getting to the main site. However, I added some code that should allow the crawler to get through and not normal users if a cookie is not set for them. However it seems to not work, the facebook one just gets redirected which I need for open graph information. I go to the debugger and type in the url for the site and it just shows that the facebook crawler gets redirected. The following verification of the code does not work at all so for example when I change my browsing session to googlebot it gets redirected.
<?php
if (!in_array($_SERVER['HTTP_USER_AGENT'], array(
'facebookexternalhit/1.0 (+https://www.facebook.com/externalhit_uatext.php)',
'facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)',
'Googlebot/2.1 (+http://www.googlebot.com/bot.html)',
'Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)',
'msnbot/2.0b (+http://search.msn.com/msnbot.htm)'
))) {
if(!isset($_COOKIE['legal'])) {
header("Location: verify.php");
}
if($_COOKIE['legal'] == "no") {
header("Location: http://www.centurycouncil.org/");
}
}
?>
This code below is the one that works for googlebot and the other search crawlers, but it doesn't work for facebook. facebook just gets redirected if facebooks tries to crawl.
<?php
if((!strpos($_SERVER['HTTP_USER_AGENT'], "Googlebot")) && (!strpos($_SERVER['HTTP_USER_AGENT'], "bingbot")) && (!strpos($_SERVER['HTTP_USER_AGENT'], "Yahoo! Slurp")) && (!strpos($_SERVER['HTTP_USER_AGENT'], "facebookexternalhit")))
{
if(!isset($_COOKIE['legal'])) {
header("Location: verify.php");
}
if($_COOKIE['legal'] == "no") {
header("Location: http://www.centurycouncil.org/");
}
}
?>