Search code examples
phpuser-agent

PHP: detect name of android device?


I want to know how I can detect the Android device the visitor uses in PHP, for eg. Galaxy S. While browsing facebook from my phone, I saw: "Install Facebook on your Galaxy S and browse faster"

So I viewed phpinfo(); located on my server from the same browser I used while browsing facebook and searched for "galaxy" text and got no matches. So how come it detected my device name? And how can I detect it on my PHP script?

Any help would be appreciated.


Solution

  • Found something like this in here :- http://forums.macrumors.com/showthread.php?t=205417

    Check whether it's useful for you not.

    <?php
    /* detect mobile device*/
    $ismobile = 0;
    $container = $_SERVER['HTTP_USER_AGENT'];
    // A list of mobile devices 
    $useragents = array ( 
    'Blazer' ,
    'Palm' ,
    'Handspring' ,
    'Nokia' ,
    'Kyocera',
    'Samsung' ,
    'Motorola' ,
    'Smartphone', 
    'Windows CE' ,
    'Blackberry' ,
    'WAP' ,
    'SonyEricsson',
    'PlayStation Portable', 
    'LG', 
    'MMP',
    'OPWV',
    'Symbian',
    'EPOC',
    ); 
    
    foreach ( $useragents as $useragents ) { 
     if(strstr($container,$useragents)) {
       $ismobile = 1;
     }
    }
    if ( $ismobile == 1 ) {
    echo "<p>mobile device</p>";
    echo $_SERVER['HTTP_USER_AGENT'];
    }
    ?>
    

    Some more stuffs here in here :- http://mobiledetect.net/

    And some more :- http://detectmobilebrowsers.mobi/

    Cheers!