答案:大家都知道如果想经统计用户访问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简介