Useful PHP snippets

Sitebee

Technical SEO
Staff member
Block visitor or bot IP address
Code:
<?php
if ($_SERVER['REMOTE_ADDR']=="90.6.400.191"){
echo "Take a hike";
exit();
}
?>

Detect mobile device
Code:
<?php
function isMobileDevice() {
    return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo
|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i"
, $_SERVER["HTTP_USER_AGENT"]);
}
if(isMobileDevice()){
    echo "Mobile Browser Detected";
}
else {
    echo "Mobile Browser Not Detected";
}
?>

Echo user-agent
Code:
 <?php
echo $_SERVER['HTTP_USER_AGENT'];
$browser = get_browser();
print_r($browser);
?>