在PHP中闲置15分钟后自动注销 [英] Automatic Logout after 15 minutes of inactive in php

查看:175
本文介绍了在PHP中闲置15分钟后自动注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户未在网站上进行任何活动,我想破坏会话. 那时5个用户之后会自动在索引页面上重定向.这怎么可能? 在php中可以进行会话处理,为此我必须维护或更新用户登录时间.

I want to destroy session if users are not doing any kind of activity on website. At that time after 5 users automatically redirect on index page. How is it possible? Is possible in php with session handling and for that I have to maintain or update user login time or not..

推荐答案

非常简单:

 if(time() - $_SESSION['timestamp'] > 900) { //subtract new timestamp from the old one
    echo"<script>alert('15 Minutes over!');</script>";
    unset($_SESSION['username'], $_SESSION['password'], $_SESSION['timestamp']);
    $_SESSION['logged_in'] = false;
    header("Location: " . index.php); //redirect to index.php
    exit;
} else {
    $_SESSION['timestamp'] = time(); //set new timestamp
}

这篇关于在PHP中闲置15分钟后自动注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆