当前位置:编程学习 > wap >>

一段用PHP检测用户终端的代码

答案:

大家都知道如果想经统计用户访问WAP网站的具体终端类型就要用到http的'HTTP_USER_AGENT' 而终端的AGENT只要得到前三个字母就可以确定终端的类型,下面用一个PHP的例子来获取用户的终端统计,代码不完全仅供大家参考 数据库为MYSQL

代码如下

<?php
$query = "SELECT * FROM wps_statistics WHERE id = 1";
$result = mysql_query($query);
$row = mysql_fetch_array ($result);
$phone_type = substr(getenv('HTTP_USER_AGENT'), 0 ,3);
switch ($phone_type) {
case "Nok":
$incagent = ++$row['nokia'];
$query = "UPDATE wps_statistics SET nokia = '$incagent' WHERE id = 1";
break;
case "Eri":
$incagent = ++$row['sonyericsson'];
$query = "UPDATE wps_statistics SET sonyericsson = '$incagent' WHERE id = 1";
break;
case "Son":
$incagent = ++$row['sonyericsson'];
$query = "UPDATE wps_statistics SET sonyericsson = '$incagent' WHERE id = 1";
break;
case "MOT":
$incagent = ++$row['motorola'];
$query = "UPDATE wps_statistics SET motorola = '$incagent' WHERE id = 1";
break;
case "SIE":
$incagent = ++$row['siemens'];
$query = "UPDATE wps_statistics SET siemens = '$incagent' WHERE id = 1";
break;
case "SAM":
$incagent = ++$row['samsung'];
$query = "UPDATE wps_statistics SET samsung = '$incagent' WHERE id = 1";
break;
case "SEC":
$incagent = ++$row['samsung'];
$query = "UPDATE wps_statistics SET samsung = '$incagent' WHERE id = 1";
break;
case "LG-":
$incagent = ++$row['lg'];
$query = "UPDATE wps_statistics SET lg = '$incagent' WHERE id = 1";
break;
case "LGE":
$incagent = ++$row['lg'];
$query = "UPDATE wps_statistics SET lg = '$incagent' WHERE id = 1";
break;
case "Pan":
$incagent = ++$row['panasonic'];
$query = "UPDATE wps_statistics SET panasonic = '$incagent' WHERE id = 1";
break;
case "Alc":
$incagent = ++$row['alcatel'];
$query = "UPDATE wps_statistics SET alcatel = '$incagent' WHERE id = 1";
break;
case "PHI":
$incagent = ++$row['philips'];
$query = "UPDATE wps_statistics SET philips = '$incagent' WHERE id = 1";
break;
case "NEC":
$incagent = ++$row['nec'];
$query = "UPDATE wps_statistics SET nec = '$incagent' WHERE id = 1";
break;
default:
$incagent = ++$row['unknown'];
$query = "UPDATE wps_statistics SET unknown = '$incagent' WHERE id = 1";
break;
}
mysql_query($query);

// Check counter / referrer settings
$query = "SELECT * FROM wps_site LIMIT 1";
$result = mysql_query($query);
$row = mysql_fetch_object($result);
$published = $row->counter;
$referer_max_nr = $row->referers;

// Display counter
$query = "SELECT * FROM wps_statistics WHERE id = 1";
$result = mysql_query($query);
$row = mysql_fetch_row ($result);
if ($published) {
$sum = $row[1]+$row[2]+$row[3]+$row[4]+$row[5]+$row[6]+$row[7]+$row[8]+$row[9]+$row[10]+$row[11];
echo _YOU_ARE_VISITOR.":<br />\n";
print "<b>$sum</b>\n";
}

// Save referrer
if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER']!="") {
$referer = $_SERVER['HTTP_REFERER'];
$date = date( "Y-m-d H:i:s" );
$query = "SELECT count(id) AS num FROM wps_referers";
$result = mysql_query($query);
$row = mysql_fetch_object($result);
$num = $row->num;
while ($num >= $referer_max_nr) {
$query = "SELECT id FROM wps_referers ORDER BY date ASC LIMIT 1";
$result = mysql_query($query);
$row = mysql_fetch_object($result);
$query = "DELETE FROM wps_referers WHERE id = '$row->id'";
mysql_query($query);
$num--;
}
$query = "INSERT INTO wps_referers VALUES ( '', '$referer', '$date' )";
mysql_query($query);
}
?>

上一个:PHP生成动态WAP页面(转二)
下一个:WAP标记语言XHTML基础教程之XHTML简介

更多图片编程知识:
更多wap疑问解答:
新人求助QPainter
为什么程序都退出了还可以收到推送?如果大多设备都可以推送那运营商怎么办?
qt 4.7 sqlserver2000 存储过程调用
关于ANDROID4.0.1编译问题!
Android FrameBuffer读屏幕30秒后mmap失败
联通粗定位用java程序如何来请求和接受数据
为什么QT运行Android平台的程序时,mouseMoveEvent事件响应的间隔时间很长??????????
android与PC蓝牙通讯
指定大小的label 内容可变,如果内容超出label的宽度,将未能显示的部分显示在另一个label上
Android调试
android如何通过wifi连接无线打印机
运行程序,release目录下产生一个乱码文件夹
分享个某机构最新安卓资料,自己验证了
service启动不起来,掉不了service connection
求助:QT5.0 没有QPrinter吗
asp
php
Delphi
Matlab
JSP
Foxpro
JS
C/C++
C#/ASP.NET
VC++
JAVA
VB
汇编语言
html/css
CGI
XML/UML
wap
网站相关
网页素材
python
微信小程序
thinkphp
如果你遇到编程学习难题:
访问www.zzzyk.com 试试
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,