无为清净楼资源网 Design By www.qnjia.com
function checkOnline($userid,$tempid=null)
{
$conn = connect();
//对于所有用户
//先设置自己为在线
$stmt = "UPDATE ".DB_NAME.".USER SET IsOnline='Y' WHERE UserID=".$userid;
$result = query($stmt,$conn);
//info($stmt);
//如果当前用户是游客
if ($tempid != null)
{
$stmt = "SELECT TempID FROM ".DB_NAME.".TEMPUSER WHERE
TempID=".$tempid;
$result = query($stmt,$conn);
//info($stmt);
//如果该游客还在线
if ($row = fetch_array($result))
{
$stmt = "UPDATE ".DB_NAME.".TEMPUSER SET
RequestTime='".getCurrentTime()."' WHERE TempID=".$tempid;
$result = query($stmt,$conn);
//info($stmt);
}
//该游客已经离线
else
{
$stmt = "INSERT INTO ".DB_NAME.".TEMPUSER
VALUES('".$tempid."','".getCurrentTime()."')";
$result = query($stmt,$conn);
//info($stmt);
}
}
//查看其他用户
//普通用户
$stmt = "UPDATE ".DB_NAME.".USER SET IsOnline='N' WHERE ".time()." -
unix_timestamp(RequestTime) > ".ONLINE_DURATION." AND UserGroupID != ".GUEST;
$result = query($stmt,$conn);
//游客
$stmt = "DELETE FROM ".DB_NAME.".TEMPUSER WHERE ".time()." -
unix_timestamp(RequestTime) > ".ONLINE_DURATION;
$result = query($stmt,$conn);
disconnect($conn);
}
//得到在线人数,分用户和游客
function getOnlineNumber()
{
$olnum = array();
$conn = connect();
$stmt = "SELECT COUNT(UserID) FROM ".DB_NAME.".USER WHERE IsOnline='Y' AND
UserGroupID != 4"; //4 为guest的用户组id
//info ($stmt);
$result = query($stmt,$conn);
$olnum['user'] = result($result,0,"COUNT(UserID)");
$stmt = "SELECT COUNT(TempID) FROM ".DB_NAME.".TEMPUSER";
//info ($stmt);
$result = query($stmt,$conn);
if ($row = fetch_array($result))
{
$olnum['guest'] = $row['COUNT(TempID)'];
}
disconnect($conn);
return $olnum; //from www.w3sky.com
}
其中的connect(), disconnect(), query(),fetch_array()函数在dbmanager.inc.PHP中
dbmanager.inc.PHP
define("DB_NAME","databasename");
define("DB_USER","user");
define("DB_PASS","pass");
define("DB_HOST","localhost");
function connect()
{
//echo "Connecting to Host:".HOST."<br>";
$conn = mysql_connect(DB_HOST,DB_USER,DB_PASS);
mysql_select_db(DB_NAME);
/*
if ($conn)
{
echo "Connect to database sucessfully. connection id:".$conn."<br>";
}
else
{
echo "Connect to database failed.<br>";
}
*/
return $conn;
}
function pconnect()
{
return mysql_pconnect(DB_HOST,DB_USER,DB_PASS);
}
function disconnect($conn)
{
$close = mysql_close($conn);
/*
if ($close)
echo "MySQL Database disconnected.<br>";
else
echo "MySQL Database disconnecting failed. Please try again.<br>";
*/
}
function query($stmt,$conn)
{
return mysql_query($stmt,$conn); //from www.w3sky.com
}
function fetch_array($result)
{
return mysql_fetch_array($result);
}
function fetch_row($result)
{
return mysql_fetch_row($result);
}
function num_rows($result)
{
return mysql_num_rows($result);
}
function result($result,$row,$field)
{
return mysql_result($result,$row,$field);
}
rule层:
rl_online.PHP
function getOnline()
{
if ($userid == 2)
{
if (session_is_registered("tempuserid"))
{
checkOnline($userid,$tempuserid);
}
}
else
{
checkOnline($userid);
}
return getOnlineNumber();
}
ui层:
ui_online.PHP
$online_num = getOnline();
echo "在线人数,注册用户".$online_num['user']."人,游客".$online_num['guest']."人";
{
$conn = connect();
//对于所有用户
//先设置自己为在线
$stmt = "UPDATE ".DB_NAME.".USER SET IsOnline='Y' WHERE UserID=".$userid;
$result = query($stmt,$conn);
//info($stmt);
//如果当前用户是游客
if ($tempid != null)
{
$stmt = "SELECT TempID FROM ".DB_NAME.".TEMPUSER WHERE
TempID=".$tempid;
$result = query($stmt,$conn);
//info($stmt);
//如果该游客还在线
if ($row = fetch_array($result))
{
$stmt = "UPDATE ".DB_NAME.".TEMPUSER SET
RequestTime='".getCurrentTime()."' WHERE TempID=".$tempid;
$result = query($stmt,$conn);
//info($stmt);
}
//该游客已经离线
else
{
$stmt = "INSERT INTO ".DB_NAME.".TEMPUSER
VALUES('".$tempid."','".getCurrentTime()."')";
$result = query($stmt,$conn);
//info($stmt);
}
}
//查看其他用户
//普通用户
$stmt = "UPDATE ".DB_NAME.".USER SET IsOnline='N' WHERE ".time()." -
unix_timestamp(RequestTime) > ".ONLINE_DURATION." AND UserGroupID != ".GUEST;
$result = query($stmt,$conn);
//游客
$stmt = "DELETE FROM ".DB_NAME.".TEMPUSER WHERE ".time()." -
unix_timestamp(RequestTime) > ".ONLINE_DURATION;
$result = query($stmt,$conn);
disconnect($conn);
}
//得到在线人数,分用户和游客
function getOnlineNumber()
{
$olnum = array();
$conn = connect();
$stmt = "SELECT COUNT(UserID) FROM ".DB_NAME.".USER WHERE IsOnline='Y' AND
UserGroupID != 4"; //4 为guest的用户组id
//info ($stmt);
$result = query($stmt,$conn);
$olnum['user'] = result($result,0,"COUNT(UserID)");
$stmt = "SELECT COUNT(TempID) FROM ".DB_NAME.".TEMPUSER";
//info ($stmt);
$result = query($stmt,$conn);
if ($row = fetch_array($result))
{
$olnum['guest'] = $row['COUNT(TempID)'];
}
disconnect($conn);
return $olnum; //from www.w3sky.com
}
其中的connect(), disconnect(), query(),fetch_array()函数在dbmanager.inc.PHP中
dbmanager.inc.PHP
define("DB_NAME","databasename");
define("DB_USER","user");
define("DB_PASS","pass");
define("DB_HOST","localhost");
function connect()
{
//echo "Connecting to Host:".HOST."<br>";
$conn = mysql_connect(DB_HOST,DB_USER,DB_PASS);
mysql_select_db(DB_NAME);
/*
if ($conn)
{
echo "Connect to database sucessfully. connection id:".$conn."<br>";
}
else
{
echo "Connect to database failed.<br>";
}
*/
return $conn;
}
function pconnect()
{
return mysql_pconnect(DB_HOST,DB_USER,DB_PASS);
}
function disconnect($conn)
{
$close = mysql_close($conn);
/*
if ($close)
echo "MySQL Database disconnected.<br>";
else
echo "MySQL Database disconnecting failed. Please try again.<br>";
*/
}
function query($stmt,$conn)
{
return mysql_query($stmt,$conn); //from www.w3sky.com
}
function fetch_array($result)
{
return mysql_fetch_array($result);
}
function fetch_row($result)
{
return mysql_fetch_row($result);
}
function num_rows($result)
{
return mysql_num_rows($result);
}
function result($result,$row,$field)
{
return mysql_result($result,$row,$field);
}
rule层:
rl_online.PHP
function getOnline()
{
if ($userid == 2)
{
if (session_is_registered("tempuserid"))
{
checkOnline($userid,$tempuserid);
}
}
else
{
checkOnline($userid);
}
return getOnlineNumber();
}
ui层:
ui_online.PHP
$online_num = getOnline();
echo "在线人数,注册用户".$online_num['user']."人,游客".$online_num['guest']."人";
标签:
php,在线人数,统计
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年11月15日
2024年11月15日
- 孙露《一抹伤HQ》头版限量[WAV+CUE][1G]
- 黄安.1989-一切从头(TP版)【天际唱片】【FLAC分轨】
- 群星.1994-浓情蜜意情歌精丫华纳】【WAV+CUE】
- 邓丽君.1983-淡淡幽情(2022环球MQA-UHQCD限量版)【环球】【WAV+CUE】
- 试音天碟《专业测试第一天碟》经典天碟精选[WAV分轨][1G]
- 试音典范 《情惹发烧情HQCD》人声发烧极品 [WAV+CUE][1G]
- 世界顶级汽车音响试音王《幸福在路上》[低速原抓WAV+CUE][1.1G]
- 老头杯第二届什么时候开始 英雄联盟第二届老头杯开赛时间介绍
- 老头杯第二届什么时候结束 英雄联盟第二届老头杯结束时间介绍
- 老头杯第二届规则是什么 英雄联盟老头杯第二届规则介绍
- 王崴-爵士听堂.蓝色波萨(HQCD)[WAV+CUE]
- 群星《欧美动听情歌·柔情第5季》2CD【DTS-WAV分轨】
- [极品珍藏]德意志进行曲集卡拉扬SACD[WAV+CUE]
- 前暴雪制作人呼吁反击DEI 玩家:夺回文化!
- 腾讯证实子公司Sharkmob大规模裁员:整个市场很低迷