所以。。。我是这样做的。。。创建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 \u once(“路径\u到\u文件/detect.php");
-
在任何需要无限次的地方使用变量$DEVICE,例如:
<?php if (!$DEVICE) {echo 'This is for all desktop devices text';} else {echo 'This is for all mobile text';}
?>
或
!!! 您也可以这样使用它(如果您需要将信息分离到不同的设备)
<?php if ($DEVICE=$iPhone) {echo 'This is for iphone devices text';} else if ($DEVICE=$Blackberry) {echo 'This is for Blackberry text';}
?>
就这样。一切巧妙都很简单!使用它并快乐!*/&燃气轮机;