English 中文(简体)
用户不活动
原标题:User Inactivity Logout PHP

我希望我的用户在十分钟的无所作为之后能够自动脱离。 我也希望所有会议都被摧毁。

如何做到这一点? 我怎么能够检查不活动,然后履行一项职能,将其 out倒?

最佳回答

也可以:

$_SESSION[ loginTime ] = time();

在每一页,当用户试图打航时,他在20分钟内无动于衷时,你可以这样说:

if($_SESSION[ loginTime ] < time()+20*60){ logout(); }
问题回答

I tired Michiels approach and got no where. On investigation I saw that the if statement simply added the expiry period to the current time so the statement never fired.

这是我的改动。

在用户中进行伐木或装上安全页时确定:

 $_SESSION[ expire ] = time()+1*60;

并且利用这一点看,到期时间是否低于目前的时间(即我们重过到期期限):

if(time() > $_SESSION[ expire ]){
 $user -> logout();
}

您可以确定会议时间,例如:

ini_set( session.gc_maxlifetime ,30);

< 您可以找到解决办法。

视服务器的快速程度和用户的多少而定,如果用户做任何事情,你可以向服务器发出请求(请点击,点击ton子,不管怎样)。 根据这一请求,更新了一张表格,列出他们最后一次活动的时间。

在一个定期的间隔期间通过桌子进行跳板的工作,并删除在任何门槛值不变的用户会议。

如果你的服务器缓慢或用户很多,你可以经常使用这一工具。

PHP的会期机制已经根据闲置时间建立了垃圾收集器。 你没有担心。

如果用户浏览到新网页,你可以把最后一段时间定为“SESSION[最后的]=时间(),并每次更新。 然后,你可以在每页都有职能时断。

function timeout()    
{
    $maxtime = 60*2; // Here , maxtime has been set to 2 minutes

if(isset($_SESSION[ lastactive ]) and (time() - $_SESSION[ lastactive ] > $maxtime )) // subtracting current time from lastactive time and seeing if it exceeded timeout limit.
{
    signout(); //logging out        
}

if(isset($_SESSION[ lastactive ]) and (time() - $_SESSION[ lastactive ] < $maxtime )) // subtracting current time from lastactive time and seeing if it exceeded timeout limit.
{   
    return 1; // timeout limit not exceeded     
}   
else
{
    if(!isset($_SESSION[ lastactive ]))
    {

        $_SESSION[ lastactive ] = time(); //if lastactive is not set
    }
}
}


$(document).ready( function()
{
setTimeout(function() { CALL LOGOUT.PHP VIA AJAX }, 720000);

});

720000 means 12 minutes ( for illustration purpose )
put this script in your header and set ur own time of inactivity
you can set what time u want , it will be work like if you set 5 minutes then when u login to system then it start count for 5 min. but if u click on any module this script will be reloaded , because when page turns then header is also reload when script is reload then it start count from 0 (initial), but if u cant access the system within 5 min. then it will load the logout.php and system will logs-out

这正是:

//set timeout period in seconds
$idleTime= 60*2;
//check to see if $_SESSION[ timeout ] is set
if(isset($_SESSION[ timeout ])){
$session_life = time() - $_SESSION[ timeout ];
if($session_life > $idleTime){
// your logout code here*
     }
}
$_SESSION[ timeout ] = time();

每次重载一页的SESSION[准时]重新启用,即每个次页的头页的档案中都包含这一内容。

最简单的办法是这样做。 如果用户不在其网站上启用某些内容,则将其改为一个登录网页

$secondsWait = 300; // these are seconds so it is 300s=5minutes
header("refresh:$secondsWait; logout.php");

转方向...标志.php的内容,销毁了任何会议,可能还发出信息,提醒用户他们为什么被拖出。

<?php
session_start();
session_unset();
session_destroy();  
?>




相关问题
why the session in iis automatically log out?

I used iis6, and when i called a function Directory.delete(), the all the session relate this website will be logged out. and i debugged the website, i found no exception. any one have ideas on this ? ...

Check session from a view in CodeIgniter

What is the best way to check session from a view in CodeIgniter, it shows no way in their user guide, otherwise I will have to make two views on everything, which is kinda weird...still a newbie to ...

Can I get the size of a Session object in bytes in c#?

Is it possible to get the size(in bytes) of a Session object after storing something such as a datatable inside it? I want to get the size of a particular Session object, such as Session["table1"], ...

提供严格分类的出席会议物体

提供严格分类的与会机会的最佳方式是什么? 我正计划转而选择矩阵,这正在促使汇编者抱怨我的幻觉方案拟订方法......

PHP Session is not destroying after user logout

I m trying to create an authentication mechanism for my PHP Application and I m having difficulty destroying the session. I ve tried unsetting the authentication token which was previously set within ...

热门标签