我有一些页面,但是我需要具有randow用户代理的用户(浏览器或平板电脑,个人计算机,..)看到随机信息。我需要检测一些设备并使用此信息进行操作。例如,对于iOS用户,我有一种信息,对于Android,我有一种信息,依此类推...对于PC /笔记本电脑用户,Android也有一种CSS(甚至徽标,事件,脚本等),而另一种CSS ,用于黑莓手机的另一个CSS等等。
我认为这对于绝对响应式设计非常重要。
答案 0 :(得分:0)
所以...我是这样做的...创建一个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';}
?>
或
!!!您也可以像这样使用它(如果您需要将信息分离到不同的设备上)
<?php if ($DEVICE=$iPhone) {echo 'This is for iphone devices text';} else if ($DEVICE=$Blackberry) {echo 'This is for Blackberry text';}
?>
就是这样。所有的创意都很简单!使用它并感到高兴! * /?>