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

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

问题描述

我的应用程序有一个问题:我的应用程序有很多表格,并且大约需要1个小时才能完成此表格,因为该表格是动态的(可以添加其他表格).问题是:我的Web服务器的会话为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中的时间设置为固定长度.因此,创建一些每5分钟左右对文件(图像或smth)进行请求的ajax代码.这样,计时器每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天全站免登陆