Php 移动设备检测

Php 移动设备检测,php,mobile,device,detect,Php,Mobile,Device,Detect,我有一些页面,但我需要使用randow用户代理(浏览器或平板电脑、pc等)的用户查看随机信息。我需要检测一些设备并用这些信息进行操作。例如,对于iOS用户,我有一种信息,对于android,还有另一种,等等。。。对于pc/笔记本电脑用户,还包括一种css(甚至是徽标、事件、脚本等),用于android另一种css,用于blackberry另一种css等等 我认为这对绝对灵敏的设计非常重要。所以。。。我是这样做的。。。创建detect.php文件并将其包含到文档中。如果有人对此有想法。。请 <

我有一些页面,但我需要使用randow用户代理(浏览器或平板电脑、pc等)的用户查看随机信息。我需要检测一些设备并用这些信息进行操作。例如,对于iOS用户,我有一种信息,对于android,还有另一种,等等。。。对于pc/笔记本电脑用户,还包括一种css(甚至是徽标、事件、脚本等),用于android另一种css,用于blackberry另一种css等等


我认为这对绝对灵敏的设计非常重要。

所以。。。我是这样做的。。。创建detect.php文件并将其包含到文档中。如果有人对此有想法。。请

<?php

$useragent = $_SERVER['HTTP_USER_AGENT']; //- Check user browser

/* Do not change anything under this line */
$iPod = stripos($useragent, "iPod"); 
$iPad = stripos($useragent, "iPad"); 
$iPhone = stripos($useragent, "iPhone");
$Android = stripos($useragent, "Android"); 
$iOS = stripos($useragent, "iOS"); 
$webOS = stripos($useragent, "webOS"); 
$Blackberry = stripos($useragent, "Blackberry");
$IEMobile = stripos($useragent, "IEMobile"); 
$OperaMini = stripos($useragent, "Opera mini"); 
$Flynx = stripos($useragent, "Flynx"); 
$Dolphin = stripos($useragent, "Dolphin");
$Meego = stripos($useragent, "Meego"); 
$Avantgo = stripos($useragent, "Avantgo"); 
$Bada = stripos($useragent, "Bada"); 
$Blazer = stripos($useragent, "Blazer");
$Compal = stripos($useragent, "Compal"); 
$Elaine = stripos($useragent, "Elaine"); 
$Fennec = stripos($useragent, "Fennec"); 
$Hiptop = stripos($useragent, "Hiptop");
$Iris = stripos($useragent, "Iris"); 
$Kindle = stripos($useragent, "Kindle"); 
$Lge = stripos($useragent, "Lge "); 
$Maemo = stripos($useragent, "Maemo");
$Midp = stripos($useragent, "Midp"); 
$Mmp = stripos($useragent, "Mmp"); 
$Netfront = stripos($useragent, "Netfront"); 
$OperaMobi = stripos($useragent, "Opera Mobi");
$Palm = stripos($useragent, "Palm"); 
$PalmOS = stripos($useragent, "Palm OS"); 
$Phone = stripos($useragent, "Phone"); 
$Plucker = stripos($useragent, "Plucker");
$Pocket = stripos($useragent, "Pocket"); 
$Psp = stripos($useragent, "Psp"); 
$Symbian = stripos($useragent, "Symbian"); 
$Treo = stripos($useragent, "Treo");
$Vodafone = stripos($useragent, "Vodafone");
$Wap = stripos($useragent, "Wap"); 
$WindowsCe = stripos($useragent, "Windows Ce"); 
$Xda = stripos($useragent, "Xda");
$Xiino = stripos($useragent, "Xiino"); 
$Kyivstar = stripos($useragent, "Kyivstar"); 
$Bolt = stripos($useragent, "Bolt"); 
$Boost = stripos($useragent, "Boost");
$Cricket = stripos($useragent, "Cricket"); 
$Docomo = stripos($useragent, "Docomo"); 
$Fone = stripos($useragent, "Fone"); 
$Mini = stripos($useragent, "Mini");
$Mobi = stripos($useragent, "Mobi"); 
$Pie = stripos($useragent, "Pie"); 
$Tablet = stripos($useragent, "Tablet"); 
$Wos = stripos($useragent, "Wos");
$Kitkat = stripos($useragent, "Kitkat"); 
$Mobile = stripos($useragent, "Mobile"); 
$GoBrowser = stripos($useragent, "GoBrowser"); 
$CLDC = stripos($useragent, "CLDC");
$uZardWeb = stripos($useragent, "uZardWeb"); 
$Doris = stripos($useragent, "Doris"); 
$Skyfire = stripos($useragent, "Skyfire"); 
$Smart = stripos($useragent, "Smart");
$MobileSafari = stripos($useragent, "Mobile Safari");

//-- Create a variable
$DEVICE = ($iPod||$iPad||$iPhone||$Android||$iOS||$webOS||$Blackberry||$IEMobile||$OperaMini||$Dolphin||$Meego||$Avantgo||$Bada||$Blazer||$Compal||$Elaine||
$Fennec||$Hiptop||$Iris||$Kindle||$Lge||$Maemo||$Midp||$Mmp||$Netfront||$OperaMobi||$Palm||$PalmOS||$Phone||$Plucker||$Pocket||$Psp||$Symbian||$Treo||$Wos||
$Vodafone||$Wap||$WindowsCe||$Xda||$Xiino||$Kyivstar||$Flynx||$Bolt||$Boost||$Cricket||$Docomo||$Fone||$Mini||$Mobi||$Pie||$Tablet||$Kitkat||$Mobile||$Smart||
$GoBrowser||$uZardWeb||$Doris||$Skyfire||$CLDC||$MobileSafari);

?>

现在您可以像这样使用它:

  • 将此文件包括到所有需要检测用户设备的文件中;如果需要,可以包含一次 例如:include_once(“path_to_file/detect.php”)

  • 在任何需要无限次的地方使用变量$DEVICE,如:

    <?php if (!$DEVICE) {echo 'This is for all desktop devices text';} else {echo 'This is for all mobile text';}
    ?>
    
    
    
  • !!!您也可以这样使用它(如果您需要将信息分离到不同的设备)

    
    

    就这样。一切巧妙都很简单!使用它并快乐!*/?>

    我看到了一个我还没有看到的问题的答案。投票不清楚。这不是一个代码/博客存储库。永远不要阅读SO规则,只发布你的东西。这样就没有问题了。解决方案在一个问题之后出现,但我没有看到一个。我们希望这里的一切都是以问答形式出现。但是,如果你能清楚地表达出符合我们正常标准的好问题,那么可以先问然后回答你自己的问题。
    <?php if ($DEVICE=$iPhone) {echo 'This is for iphone devices text';} else if ($DEVICE=$Blackberry) {echo 'This is for Blackberry text';}
    ?>