2011-11-30 115 views
3

我閱讀了此主題: Simplest way to detect a mobile device 關於如何知道瀏覽器是否是移動設備。一般的代碼是這樣的:如何在PHP中檢測移動設備和平板電腦

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

的問題是,我想對待片(新iPad & XOOM)。

我看到那裏有,我還沒有測試了isIpad()函數 - 但是這仍然沒有解決平板電腦和手機之間的差異。

有什麼想法?

感謝, 阿龍

回答

4

使用

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

您可以參考此頁面瞭解更多信息http://code.google.com/p/php-mobile-detect/

+0

其ASLO不工作 – Arif

+0

@Arif請提供更多細節,請確保您遵守所有的指引在給定的鏈接。 – Sid

+0

一切工作正常!謝謝 –

2

只有這樣,才能做到這一點是User-Agent:串的一個巨大的查找表。

get_browser()可能會能夠做到你想要什麼,但你需要確保你保持browscap文件非常最新的 - 新的平板機型被公佈的每週的基礎上。

另外可能還有一些JavaScript的方式來做到這一點(雖然我不知道是什麼,可能是),但

  • 你仍然要保持一個非常大的查找表更新
  • 你永遠不應該依賴於在JavaScript上的任何功能。
0
$detect = new Mobile_Detect; 
$deviceType = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'computer'); 
echo $deviceType; 
相關問題