防止会话在非活动用户的 PHP 会话中过期 [英] Prevent session expired in PHP Session for inactive user

查看:37
本文介绍了防止会话在非活动用户的 PHP 会话中过期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有问题:我的应用程序有很多表单,需要大约 1 小时才能完成此表单,因为表单是动态的(可以添加其他表单).问题是:我的网络服务器的会话是 24 分钟.当用户填写表单时,他们花费了太多时间并且会话超时,因为服务器识别出用户处于非活动状态.表单提交时很烦人,大部分数据丢失并且用户返回到登录页面.我试图用这个代码让我的会话在 10 小时后过期:

I have a problem with my application: my application has many forms and need about 1 hour to finish this form because the form is dynamic (can add other forms). The problem is: the session of my web server is 24 minutes. When user fill the form, they spent so much time and the session timed out because server recognize that the user is inactive. It's very annoying when form submitted, most data was lost and the user is returned to the login page. I have tried to make my session expired in 10 hours with this code:

ini_set('session.gc_maxlifetime', '36000');

但它在我的服务器中不起作用,我的服务器是否可能阻止 ini_set() 函数?

But it's not working in my server, is it possible my server preventing ini_set() function?

那么,我应该怎么做才能解决这个问题?我可以防止会话超时以便会话可以扩展到 10 小时吗?或者我可以禁用会话过期吗?

So, what should I do for solving this problem? Can I prevent session timeout so that the session can be expanded to 10 hours? Or can I disable session expiration?

谢谢

推荐答案

不是将 ini 中的时间设置为固定长度,而是提醒会话超时在重新加载时重置.因此,创建一些 ajax 代码,每 5 分钟左右对文件(图像或 smth)执行一次请求.这样,计时器每 5 分钟重置一次,用户可以花一天时间填写您的表单.

Instead of setting the time in ini to a fixed length, remind that session timeout is reset on reload. So create some ajax code that does a request every 5 minutes or so to a file (image or smth). This way the timer is reset every 5 minutes and users can spend a day filling out your forms.

这篇关于防止会话在非活动用户的 PHP 会话中过期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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