PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I'm having trouble getting pages indexed in google because I have restricted access to the webpages based on a cookie value. I needed to do this because it's an alcohol related website and needs to validate the user age before displaying a page. All my cookie and age validation code works fine but when I try to detect googlebot and allow it to view a page using an 'include' file the pages fail to index in google.
Heres my include code
$host = gethostbyaddr("66.249.66.1");
if ( substr($host, (strlen($host)-13)) == 'googlebot.com' )
{
echo "It's a googlebot!\n";
}
I can confirm that your condition 2 statement is proper, and I don't see your first condition failing. Any value returned by strstr() that is not a null/negative value will evaluate to "== true". Can you verify in your logs that the googlebot is actually accessing the page in question? You may see the googlebot being sent away from your site by a robots.txt file before it can even access this page. I'm not sure, just throwing a couple of possibilities your way.
Thanks for the response. I'm relatively new to this "user agent/googlebot detection" but I have uploaded your correction to my code to see if it works. One article I read said this. (not sure how this affects my code. Do I need to validate a series of IP numbers.)
No, it can't. Read the manual.
Also, read the manual about PHP operators - there is a big difference between == and === operators.
Correct, VladSun. My mistake for not clarifying: in this case it makes no difference to the outcome of his code to use !== or just checking for any value at all. I do not mean to imply that !== is the same as != (in the same way that == is not the same as ===).
andyhoneycutt wrote:Correct, VladSun. My mistake for not clarifying: in this case it makes no difference to the outcome of his code to use !== or just checking for any value at all. I do not mean to imply that !== is the same as != (in the same way that == is not the same as ===).
Ooops, sorry!
I thought it was substr() ...
There are 10 types of people in this world, those who understand binary and those who don't