相思资源网 Design By www.200059.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.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com
暂无也谈php网站在线人数统计的评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。