PHP – Information About a User Device

The following php example helps you get the information about the device, either it's tablet,
mobile or desktop.

Code Example:

function userAgent($ua){
    $iphone = strstr(strtolower($ua), 'mobile'); //Search for 'mobile' in user-agent (iPhone have that)
    $android = strstr(strtolower($ua), 'android'); //Search for 'android' in user-agent
    $windowsPhone = strstr(strtolower($ua), 'phone'); //Search for 'phone' in user-agent (Windows Phone uses that)
    function androidTablet($ua){ //Find out if it is a tablet
        if(strstr(strtolower($ua), 'android') ){//Search for android in user-agent
            if(!strstr(strtolower($ua), 'mobile')){ //If there is no ''mobile' in user-agent (Android have that on their phones, but not tablets)
                return true;
    $androidTablet = androidTablet($ua); //Do androidTablet function
    $ipad = strstr(strtolower($ua), 'ipad'); //Search for iPad in user-agent
	$kindle = strstr(strtolower($ua), 'kindle'); //Search for iPad in user-agent
    if($androidTablet || $ipad || $kindle){ //If it's a tablet (iPad / Android / Kindly)
        return 'tablet';
    elseif($iphone || $android || $windowsPhone){ //If it's a phone and NOT a tablet
        return 'mobile';
    else{ //If it's not a mobile device
        return 'desktop';
echo $http_user_agent = userAgent($_SERVER['HTTP_USER_AGENT']);

Post to Twitter Post to Digg Post to Facebook Post to Google Buzz Send Gmail

Leave a Comment

Your email address will not be published. Required fields are marked *