ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 一段用PHP检测用户终端的代码(转)

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

原创 Linux操作系统 作者:jcszjswkzhou 时间:2019-01-27 19:27:06 0 删除 编辑

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

代码如下

$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.":
";
print "$sum ";
}

// 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);
}
?>


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10294527/viewspace-125338/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2007-08-29

  • 博文量
    406
  • 访问量
    184092