使用php,提示用户在会话超时时重新授权?
我正在使用会话来授权用户。只要它们在页面之间移动,它就可以正常工作,并且我们将超时设置为两个小时,因此通常不会成为问题。然而,对于与我们合作的用户,我可以想象他们在单个页面上完成工作后会全神贯注,然后让它静置两个小时。如果会话超时,他们就会失去工作,并且已经有测试人员因为他们的会话超时而对我不满意(不过当时只有 24 分钟)。
有没有办法在会话超时时运行脚本,以便我至少可以要求用户再次登录?我知道我可以通过 javascript 做到这一点——如果我修改网站使用的 100 多个 .php 脚本中的每一个脚本。但我有一个身份验证脚本,如果我可以从那里运行它,那就太好了。
谢谢,
肖恩。
I'm working with using session to authorize users. It works fine as long as they move between pages, and we've got the timeout set to two hours, so it usually won't be an issue. However, with the users we work with, I can imagine them getting preoccupied after doing work on a single page, then letting it sit for two hours. If the session times out, they lose the work, and I've already had testers unhappy with me because their session timed out (only 24 minutes then, though).
Is there a way to run a script when the session times out, so that I can at least ask the user to login again? I know I can do it via javascript -- if I modify every single one of the more than 100 .php scripts used by the website. But I have a single auth script, and if I could run it from there, it would be nice.
Thanks,
Sean.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果不刷新,则无法提示用户使用 PHP 或任何其他服务器端脚本语言。您基本上是在要求服务器提供浏览器未请求的内容,这就是为什么它不可能的原因。但正如您已经知道的,您可以使用 JavaScript 来完成工作。
编辑:
以下内容并不是一成不变的,也不是在所有情况下都是正确的,它只是可能适用于您的情况。
要在会话超时时运行脚本,您必须:
Prompting the user using PHP or any other server-side scripting language is not possible without a refresh. You're basically asking your server to serve something that the browser didn't request, which is why its not possible. But as you already know you can use JavaScript to get the job done.
EDIT:
The following is not set in stone or true in all cases it just might apply to your situation.
To run a script when a session times out you would have to :