The below I have put together as an experiment, I have profiles on my site that are password protected. I would still like them to be crawled by google. The script is taken from here and basically does a reverse dns lookup to verify if a googlebot is real or fake. I am then using this logic to allow google entry to my dynamic page by skipping the 'restrict-access.php' include which checks to see if someone is logged in or not.My question is..1. Is this viable?  2. is the code solid/safe?<?phpfunction validateGoogleBotIP($ip){    $hostname = gethostbyaddr($ip); //crawl-66-249-66-1.googlebot.com    return preg_match('/\.googlebot\.com$/i', $hostname);}if (strpos($_SERVER['HTTP_USER_AGENT'], 'Google') !== false) {    if (validateGoogleBotIP($_SERVER['REMOTE_ADDR'])) {        // its google - let them in    } else {        exit('You are not authorised to view this page');    }} else {    require_once('php-includes/restrict-access.php');    if (isset($_GET['user_id'])) {        if (!ctype_digit($_GET['user_id']))            exit('You are not authorised to view this page');    } else {        exit('You are not authorised to view this page');    }}?>
Allowing googlebot to crawl a password protected page
php5;networking
It makes more sense to define an isGoogleBotRequest() function, because that is what you want to know, and the IP address verification is just one detail of that.  Furthermore, I recommend that you define an getAuthorisedUser() function in restrict-access.php so that you don't have to write two if statements for that.You have three places where you exit with the unauthorised error message.  Ideally, there should be one place where you do that.Furthermore, instead of just dying, your script should output a 403 Forbidden HTTP header, and exit successfully.<?phpfunction isGoogleBotRequest(){    // Check User-Agent and verify using reverse-DNS lookup as recommended    // in https://support.google.com/webmasters/answer/80553    if (strpos($_SERVER['HTTP_USER_AGENT'], 'Google') !== false) {        $hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);        return preg_match('/\.googlebot\.com$/i', $hostname);    }    return false;}if (!isGoogleBotRequest()) {    require_once('php-includes/restrict-access.php');    if (!getAuthorisedUser()) {        header('HTTP/1.0 403 Forbidden');        echo 'You are not authorised to view this page';        exit;    }}?>