<div class="demo">
<div id="total">当前在线:<span id="onlinenum"></span></div>
<ul id="onlinelist">
<li><img src="loader.gif"></li>
</ul>
</div>
.demo{width:150px; margin:20px auto; font-size:14px}
#total{padding:6px 10px; background:#090 url(arr.png) no-repeat right top; color:#fff;
cursor:pointer; -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px;
-moz-box-shadow:0 0 3px #ccc; -webkit-box-shadow:0 0 3px #ccc;box-shadow:0 0 3px #ccc;}
#onlinelist{background:#f7f7f7; border:1px solid #d3d3d3; display:none; -moz-border-radius:5px;
-webkit-border-radius:5px; border-radius:5px; -moz-box-shadow:0 0 3px #ccc;
-webkit-box-shadow:0 0 3px #ccc;box-shadow:0 0 3px #ccc;}
#onlinelist li{height:20px; line-height:20px;padding:4px 6px;border-bottom:1px dotted #d9d9d9}
#onlinelist li span{float:right}
#onlinelist li:hover{background:#fff}
CREATE TABLE IF NOT EXISTS `online` ( `id` int(11) NOT NULL AUTO_INCREMENT, `ip` varchar(30) NOT NULL, `province` varchar(64) NOT NULL, `addtime` int(10) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
include_once('connect.php'); //连接数据库
$ip = get_client_ip(); //获取客户端IP
$time = time();
//查询表中是否有ip为当前访客IP的记录
$query = mysql_query("select id from online where ip='$ip'");
if(!mysql_num_rows($query)){//如果不存在访客IP
if($_COOKIE['geoData']){//如果存在cookie,则获取用户的区域
$province = $_COOKIE['geoData']; //区域(省份)
}else{
$api = "http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=$ip";
$json = file_get_contents($api);//
$arr = json_decode($json,true);//解析json
$province = $arr['province'];//获取省份
setcookie('geoData',$province,$time+600); //设置cookie,设置过期时间为10分钟
}
//将访客信息插入到数据表中
mysql_query("insert into online (ip,province,addtime) values ('$ip','$province','$time')");
}else{//如果存在,则更新该用户访问时间
mysql_query("update online set addtime='$time' where ip='$ip'");
}
//删除已过期的记录
$outtime = $time-600;
mysql_query("delete from online where addtime<$outtime");
//统计总记录数,即在线用户数
list($totalOnline) = mysql_fetch_array(mysql_query("select count(*) from online"));
echo $totalOnline;//输出在线总数
mysql_close();
function get_client_ip() {
if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
$ip = getenv("HTTP_CLIENT_IP");
else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"),
"unknown"))
$ip = getenv("HTTP_X_FORWARDED_FOR");
else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
$ip = getenv("REMOTE_ADDR");
else if (isset ($_SERVER['REMOTE_ADDR']) &&
$_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
$ip = $_SERVER['REMOTE_ADDR'];
else
$ip = "unknown";
return ($ip);
}
include_once('connect.php');//连接数据库
//查询区域统计
$sql = "select province,count(*) as total from online group by province order by total desc";
$result = mysql_query($sql);
while($row=mysql_fetch_array($result)){
$list[] = array(
'province' => $row['province'],
'total' => $row['total']
);
}
echo json_encode($list);//以json格式输出
$(function(){
$("#onlinenum").load("online.php");
$(".demo").hover(function(){
$("#onlinelist").slideDown("fast");
var str = '';
$.getJSON("geo.php",function(json){
$.each(json,function(index,array){
str = str + "<li><span>"+array['total']+"</span>"+array['province']+"</li>";
});
$("#onlinelist").html(str);
});
},function(){
$("#onlinelist").slideUp("fast");
});
});
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有