如何在 php 中检测移动浏览器


How to detect the mobile browsers in php

我尝试了这段代码 这段代码来检测移动设备中的浏览器

<?php
function isMobile() {
    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 the user is on a mobile device, redirect them
if(isMobile())
{
  echo 'mobile';
}
else
{
    echo 'desktop';
}
?>

但是它没有检测到移动浏览器,任何人都可以告诉我如何解决此问题

http://detectmobilebrowsers.com/也很好用 - 或者亚当的建议也很好。