使用php 怎么才能判断用户在线,离线 我做了个类似论坛的程序,要显示用户的在线状态和离线状态,请教高手,指点一下 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 /********************************* *1.统计谁在线。 *2.后台显示有多少个客户在线 并且在什么页面关闭了网站 *3.2009-10-15 ********************************/function whos_online(){// $full_name; if(isset($_SESSION["user_names"])) { $wo_full_name=$_SESSION["user_names"]; }else { $wo_full_name="Guest"; } $wo_ip_address = getenv('REMOTE_ADDR'); //获取ip地址 $wo_last_page_url = getenv('REQUEST_URI'); //获得操作路径 $current_time = time(); $xx_mins_ago = ($current_time - 900); //获得15分钟前的日期 $sessionID=getsession(); $sql_delete_whos_online="delete from whos_online where time_last_click<'$xx_mins_ago'"; mysql_query($sql_delete_whos_online) or die("whos_online delete error"); //删除900秒前的数据 $sql_count_whos_online="select * from whos_online where session_id='$sessionID'"; $result_count_whos_online=mysql_query($sql_count_whos_online) or die("whos_online select error"); if($result_count_whos_online and mysql_num_rows($result_count_whos_online)>0) { $sql_update_whos_online="update whos_online set full_name='$wo_full_name',ip_address='$wo_ip_address',time_last_click='$current_time',time_last_url='$wo_last_page_url' where session_id='$sessionID'"; mysql_query($sql_update_whos_online) or die("whos_online update error"); } else//跟新数据 { $sql_insert_whos_online="insert into whos_online(full_name,session_id,ip_address,time_entry,time_last_click,time_last_url)" . " values('$wo_full_name','$sessionID','$wo_ip_address','$current_time','$current_time','$wo_last_page_url')"; mysql_query($sql_insert_whos_online) or die("whos_online insert error"); }}echo whos_online(); //判断谁在线 你好 请问我运行的时候会出现Call to undefined function getSession() in D:\wamp\www\weibo\init.php on line 51这是怎么回事????谢谢了 我的getSession()是一个函数...function getsession(){ $sessionID=session_id(); //用户标示 return $sessionID;} 他这个是获取你最后一次页面刷新的记录.一般的电子商务网站,在后台不是可以查看那在线客户吗? 那个功能就是获取前台 客户的浏览器session_id如果客户在15分钟内 保持在一个页面没有改变,程序也会认为他掉线了.但是如果客户立即关闭了,你在后台要隔900秒才能知道. php+js倒计时循环 求开源商城!来者有分! 求一正则 连接数据库有关的错误 php 自己写mvc 框架 url重写 等怎么写 snoopy获取微信分享链接页面的问题 如何在自己的网站上实现百度的第三方登录 求各路大神帮忙指点小弟这儿哪里出错了。就是连接不上数据库 ecshop 模板制作求助! PHP备注删除 代码就无法运行 Smarty的一个小问题,谢谢 唉,还得努力,谁弄过呵
/*********************************
*1.统计谁在线。
*2.后台显示有多少个客户在线 并且在什么页面关闭了网站
*3.2009-10-15
********************************/
function whos_online()
{
// $full_name;
if(isset($_SESSION["user_names"]))
{
$wo_full_name=$_SESSION["user_names"];
}else
{
$wo_full_name="Guest";
}
$wo_ip_address = getenv('REMOTE_ADDR'); //获取ip地址
$wo_last_page_url = getenv('REQUEST_URI'); //获得操作路径
$current_time = time();
$xx_mins_ago = ($current_time - 900); //获得15分钟前的日期
$sessionID=getsession();
$sql_delete_whos_online="delete from whos_online where time_last_click<'$xx_mins_ago'";
mysql_query($sql_delete_whos_online) or die("whos_online delete error"); //删除900秒前的数据
$sql_count_whos_online="select * from whos_online where session_id='$sessionID'";
$result_count_whos_online=mysql_query($sql_count_whos_online) or die("whos_online select error");
if($result_count_whos_online and mysql_num_rows($result_count_whos_online)>0)
{
$sql_update_whos_online="update whos_online set full_name='$wo_full_name',ip_address='$wo_ip_address',time_last_click='$current_time',time_last_url='$wo_last_page_url' where session_id='$sessionID'";
mysql_query($sql_update_whos_online) or die("whos_online update error");
}
else//跟新数据
{
$sql_insert_whos_online="insert into whos_online(full_name,session_id,ip_address,time_entry,time_last_click,time_last_url)" .
" values('$wo_full_name','$sessionID','$wo_ip_address','$current_time','$current_time','$wo_last_page_url')";
mysql_query($sql_insert_whos_online) or die("whos_online insert error");
}
}
echo whos_online(); //判断谁在线
这是怎么回事????谢谢了
function getsession()
{
$sessionID=session_id(); //用户标示
return $sessionID;
}
如果客户在15分钟内 保持在一个页面没有改变,程序也会认为他掉线了.
但是如果客户立即关闭了,你在后台要隔900秒才能知道.