How to detect between mobile & tablets in PHP

一世执手 提交于 2019-12-07 08:10:29

问题


I read on this thread: Simplest way to detect a mobile device on how to know if the browser is a mobile device. the general code is this:

<?php include("Mobile_Detect.php"); include("demoData.php");
$detectIsMobile = new Mobile_Detect(); ?>

The problem is that I want to treat tablets (iPad & xoom).

I saw there that there is a isIpad() function that I have tested yet - but that still doesn't solve the difference between tablets and mobile phones.

Any idea?

thanks, Alon


回答1:


Use

<?php
    if($detect->isTablet()){
        // any tablet
    }
?>

You can refer this page for more info http://code.google.com/p/php-mobile-detect/




回答2:


The only way to do this is with a huge lookup table of User-Agent: strings.

get_browser() would probably be able to do what you want, but you would need to make sure that you keep the browscap file very up to date - new tablet models are being released on a weekly basis.

Alternatively there may some Javascript way to do it (although I don't know what that might be) but

  • you would still have to keep a very large lookup table updated
  • you should never rely on Javascript for any kind of functionality.



回答3:


$detect = new Mobile_Detect; 
$deviceType = ( $detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'computer');
echo $deviceType;


来源:https://stackoverflow.com/questions/8328448/how-to-detect-between-mobile-tablets-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!