会话过期后运行查询 [英] Run query after session expire

查看:51
本文介绍了会话过期后运行查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个 php 代码,它可以在特定会话即将到期后运行查询,

I need a php code that will run a query after a specific session is going to expire,

if(!isset($_SESSION['test'])) query;

类似的东西,但确实适用于会话过期.

something like that but does work with session expire.

推荐答案

你会遇到的问题:会话不只是自己过期,会话em> 如果用户等待时间过长,则在下一页加载时过期.由于浏览器和服务器之间的请求(用户操作)之间没有通信,因此服务器不会知道例如用户刚刚关闭了浏览器(或在网站保持打开状态时洗碗).

The problem you'll run into: a session doesn't just expire by itself, a session is expired on the next page load if the user waited too long. As there's no communication between browser and server between requests (user action), the server won't know if e.g. the user just closed the browser (or is doing the dishes while the website remains open).

所以我想你的代码没有问题,因为它会告诉你 sessin is 是否在下一个页面加载时过期(只要有下一个页面加载:)).

So I guess there's nothing wrong with your code as it'll tell you if the sessin is expired on the next pageload (as long as there is a next pageload :)).

如果您真的需要确保查询在会话过期后运行,我想您必须将会话保存到数据库并在每个页面加载时运行清理"脚本运行您的查询并摆脱过期的会话.(例如,保存lastUserAction"并将其与您的会话限制进行比较)

If you really need to make sure, the query runs after a session expired, I guess you'll have to save your sessions to a database and run a "cleanup"-script on each pageload to run your query and get rid of expired sessions. (e.g. save "lastUserAction" and compare that to whatever your session-limit is)

这篇关于会话过期后运行查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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