I want to ensure that my site users are only using chrome and firefox. My hosting company reported unnecessary hit to my site by users coming with empty user agent. This not DOS Attack.
I just want to block all users with empty user agents.
currently the code checks and ensure that only firefox and chrome broswers can access my site.
My question is how do I check users with empty useragent. This is my check for that. Is it right?
//check if useragent is empty
if($agent==''){
echo "user agent is empty. access block";
}
below is the code so far which ensures that only firefox and chrome are allowed access
$arr_browsers = ["Firefox", "Chrome"];
$agent = $_SERVER['HTTP_USER_AGENT'];
$user_browser = '';
foreach ($arr_browsers as $browser) {
if (strpos($agent, $browser) !== false) {
$user_browser = $browser;
break;
}
}
//check if the browser is not in array
if ( ! ( in_array($user_browser, $arr_browsers) ) ) {
echo "you browser are not allowed. This work fine";
}