php 脚本注销太快

发布于 2024-11-08 14:49:35 字数 779 浏览 0 评论 0原文

我正在一个项目中工作,另一个开发人员编写了代码,而用户像往常一样登录 session_start() 然后他像下面一样检查:

    if($a['userName'] == $username && $a['password'] == $pwd)   
{
                $_SESSION['id'] = $a['id'];         ?>       <script language="javascript"type="text/javascript">window.location="host.php";</script> }     else    {       
$msg= "Invalid Username Password";  
}

当用户想要在几秒钟后使用该表单时,它会注销,用户可以不提交数据。

我尝试增加会话生命周期:

$sessionCookieExpireTime=8*60*60;
session_set_cookie_params($sessionCookieExpireTime); 

并且还尝试在运行时增加会话生命周期,如下所示:

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

最后尝试增加 php.ini 会话生命周期。 不幸的是这些没有用。

我应该提到的一件事是,没有用于注销问题的 session_destroy() 。

提前致谢。

I was working in a project where another developer wrote the code,while a user is login the session_start() as usual and then he is cheking like belows:

    if($a['userName'] == $username && $a['password'] == $pwd)   
{
                $_SESSION['id'] = $a['id'];         ?>       <script language="javascript"type="text/javascript">window.location="host.php";</script> }     else    {       
$msg= "Invalid Username Password";  
}

And when a user want to use the form after couple of seconds its logout and user can not submit data.

I have tried increasing session life time duration:

$sessionCookieExpireTime=8*60*60;
session_set_cookie_params($sessionCookieExpireTime); 

And also tried with increasing session lifetime in runtime like below:

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

And finally tried by increasing php.ini session lifetime .
Unfortunately those did not work.

One thing I should mention that,there is no session_destroy() for logout issues.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

万劫不复 2024-11-15 14:49:35

您正在使用什么类型的服务器?

在运行多个使用共享会话目录的站点的共享服务器上,session.gc_maxlifetime 实际上是访问该共享目录的所有站点的最短生命周期。

如果问题出在开发服务器上,请找出会话文件的存储位置并查看它们发生了什么。

存储会话的目录也可能不可写。在这种情况下,会话变量永远不会存储在第一位。

在所有三种情况下:尝试将会话文件存储在不同的目录中。在代码中,您必须在调用 session_start() 之前使用 session_save_path() 设置会话目录。

What kind of server are you working on?

On a shared server that runs multiple sites that use a shared session directory the session.gc_maxlifetime is in effect the shortest lifetime of all sites accessing that shared directory.

If the problem is on a development server, find out where the session files are stored and look at what happens to them.

It is also possible that the directory where the sessions are stored is not writeable. In that case the session variable is never stored in the first place.

In all three cases: try to store the session files in a different directory. In code you have to set the session directory with session_save_path() before you call session_start().

世界等同你 2024-11-15 14:49:35

当用户空闲活动一段时间后就会发生超时。除非使用session_destroy,否则无法自动注销。

您的代码可能是
$a['id'];

偶然返回 null。
此外,您还需要检查哪个页面被注销。
给出完整的代码可能很容易识别问题。

The timeout occurs when user idle activity for certain time. There is no way to logout automatically unless using session_destroy.

It may be possible that your code
$a['id'];

returns null by chance.
Also, you need to checkout which page is getting logged out.
Giving the full code may be easy to identify the issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文