TOP

How to find out that the user visited the site from a mobile device?

YouLibreCalc for Excel logo

Description

To find out that the user is using a mobile device to view the site, you can create a custom PHP function that will check the "HTTP_USER_AGENT" parameter.


PHP code

function check_smartphone() {
 
    $phone_array = array('iphone', 'android', 'pocket', 'palm', 'windows ce', 'windowsce', 'cellphone', 'opera mobi', 'ipod', 'small', 'sharp', 'sonyericsson', 'symbian', 'opera mini', 'nokia', 'htc_', 'samsung', 'motorola', 'smartphone', 'blackberry', 'playstation portable', 'tablet browser');
    $agent = strtolower($_SERVER['HTTP_USER_AGENT']);
 
    foreach ($phone_array as $value) {
        if (strpos($agent, $value) !== false) return true;
    }
    return false;
}