ארכיון פוסטים עם התג "strpos"

Check if user agent is GoogleBot

יום ראשון, 18 בנובמבר, 2012

In this post i will provide an example in php how to check if the request is made by Google search engine, typicily each browser have its own signature for example Mozila ,Explorer,Safari we are capable of reaing the user agent information from server variable called HTTP_USER_AGENT ,  Google search bots are identified with speicial UserAgent named Googlebot here is an example for a code that check the user Agent

<?php

if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Googlebot' ) !== false )

{

// paste your email address here

$my_email = 'xxx@Gmail.com';

// notify via email

mail($my_email,'[Notification]Googlebot Visit', 'Googlebot has just visited your website WEBSITE_NAME: '.$_SERVER['REQUEST_URI']);

}

else

{

echo ("<!– Regular user not google –>");

}