【问题标题】:What is the script to to detect mobile devices检测移动设备的脚本是什么
【发布时间】:2010-08-12 10:38:59
【问题描述】:

我必须为我的网站制作 2 个版本,即 1 个手机版本和 1 个 PC 版本。所以我有一个脚本如下:-

<?php 
if ( stristr($ua, "Windows CE") or stristr($ua, "AvantGo") or 
     stristr($ua,"Mazingo") or stristr($ua, "Mobile") or stristr($ua, "T68") or
     stristr($ua,"Syncalot") or stristr($ua, "Blazer") or 
     stristr($ua,"Mozilla") or stristr($ua,"Firefox") )
{
     $DEVICE_TYPE="MOBILE";
}
if (isset($DEVICE_TYPE) and $DEVICE_TYPE=="MOBILE") 
{
    $location='mobile/entry.html';
    header ('Location: '.$location);
    exit;
}
else
{ 
    $location='entry.html';
    header ('Location: '.$location);
    exit;
}
?>

此脚本在我的 PC 上运行良好,但如果我尝试从移动设备访问我的网站,我无法重定向到我想要的同一页面。

谁能帮我解决这个问题?

提前致谢。

【问题讨论】:

标签: php html


【解决方案1】:

这是您的解决方案:

http://code.google.com/p/php-mobile-detect2/

【讨论】:

    【解决方案2】:

    【讨论】:

      【解决方案3】:

      最好的选择不是尝试基于用户代理嗅探进行重定向,而是将您的移动内容放到特定的 url 上,并使这些选项可用。用户代理嗅探在某种程度上是可以的,但你不能 100% 依赖它。与此相关,PPK's post on javascript detection 很好读。

      也就是说,如果您一心想要进行用户代理重定向,您将需要有一些方法来更新您的设备列表和用户代理字符串 - 类似 codeigniter 的 user agent class 会更多从长远来看很有用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-01-26
        • 1970-01-01
        • 2010-09-06
        • 2012-08-31
        • 2010-11-20
        • 2021-04-14
        相关资源
        最近更新 更多