简体   繁体   English

在浏览器上关闭注销

[英]On browser close logout

There are many questions asked about this problem but i suppose none of them could help me in my case. 关于这个问题有很多问题要问,但是我想这些问题都无法帮助我。 I will show you my login form , my main page, showing active users , and am little confused about starting lastTimeUpdate function to it. 我将向您显示我的登录表单,我的主页,显示活动用户,并对启动lastTimeUpdate函数感到困惑。 Here is my main contetnt form, the problem is that there is a list of active users if user is active his name is displayed if not - not displayed, but if user exits browser, session destroys, but doesnt log out: 这是我的主要竞争形式,问题是如果用户处于活动状态,则存在一个活动用户列表,如果未显示,则显示他的名字-不显示,但是如果用户退出浏览器,会话破坏但不注销:

<?php
include 'config.php';
//include 'logout.php';
$query = "SELECT * FROM userinfo WHERE `ifactive` = 1";
if(isset($_SESSION['uname'])){

$result = mysql_query($query);
echo "<div id=maincontenttopleft>
<p>Active users</p>";
echo "<div id=acuser><table  id=activeusers>"; 

while($row = mysql_fetch_array($result)){ 
echo  "</td><td>" . $row['name'] . "</td></tr>";
}
echo "</table></div>"; 
mysql_close();
}
//if (session_destroy()) {
//mysql_query("SELECT * FROM `userinfo` WHERE `ifactive` = 1 AND `uname` !=  
'$_SESSION[uname]'");
//mysql_query("UPDATE `userinfo` SET `ifactive` = 0 WHERE `uname` !=  
'$_SESSION[uname]'") or die(mysql_error());
//}
if (!isset($_SESSION['uname'])) {
$_SESSION['uname'] = time();
} else if (time() - $_SESSION['uname'] > 10) {
 // session started more than 30 minutes ago
 //mysql_query("SELECT * FROM `userinfo` WHERE `ifactive` = 1 AND `uname` =  
'$_SESSION[uname]'");
//mysql_query("UPDATE `userinfo` SET `ifactive` = 0 WHERE `uname` = 
'$_SESSION[uname]'") or die(mysql_error());
session_regenerate_id(true);    // change session ID for the current session an    
invalidate old session ID
$_SESSION['uname'] = time();  // update creation time
}
?>

I want to check if there is a destroyed session, to take the name of this session end according to the name to set my boolean (ifactive) to zero. 我想检查是否存在被破坏的会话,以便根据名称将该会话结束的名称设置为布尔值(如果处于活动状态)为零。 Can you help me about the logic of it. 您能帮我谈一下它的逻辑吗?

You'll then need to save the session_id of every user in the database. 然后,您需要将每个用户的session_id保存在数据库中。 And then inside a cron for instance, have a script checking the existence of the file associated to each session. 例如,在cron内部,有一个脚本来检查与每个会话相关联的文件是否存在。

Here is how you find your sessions folder if you don't want to mess in your config files : 如果您不想弄乱配置文件,可以通过以下方法找到会话文件夹:

<?php

echo session_save_path ();

?>

Your cron script could then save the results in a txt file which would be easier for your website script to read (or better yet, save it in memory so it's faster - checkout redis). 然后,您的cron脚本可以将结果保存到一个txt文件中,这将使您的网站脚本更易于阅读(或者更好的是,将其保存在内存中,以便更快-签出redis)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM