且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

CodeignitEr会话不与AJAX一起使用

更新时间:2023-09-19 11:01:28

如果您使用了基于CI后端构建的AJAX沉重的网络应用程序,您可能已经注意到过早的会话过期,即使您的过期设置为永不过期($这显然是由于AJAX请求没有重新生成会话和明显的冲突。这是因为它是一个非常简单的应用程序/ config / config.php。长篇小说,上个月有一个补丁介绍没有多少夸耀,这(到目前为止)似乎是为我工作。



替换您的系统/库/会话。 php文件与这里找到的(CI的git):



https://raw.github.com/EllisLab/CodeIgniter/b211adee89f5fd2192051e9c0826146bd150f469/system/libraries/Session.php


The issue here is I am trying to login into my system via ajax. Let me explain it to your first.

when my user puts in his login details it will be send to the server via Ajax request and then once it gets verified i create an entry into a session and save the information like userid and logged_in flag.

And then i return those value through Json back to user which is processed by a piece of javascript and redirect the user to dashboard.

If the user is not authenticated it shows an error.

But now whats happening here is. When i create a session variable and when the user is redirected to the dashboard. Sometimes it does not create the session variables and thats why i cant show logout button?

any help will be appreciated.

If you’ve used AJAX-heavy web apps built on a CI backend, you might have noticed premature session expiration, even if you’re expiration was set to never expire ($config['sess_expiration'] = 0; in application/config/config.php)

This was apparently due to AJAX requests not regenerating sessions, and apparent collisions. Long story short, last month there was a patch introduced without much fanfare, which (so far) seems to be working for me.

Replace your system/libraries/Session.php file with the one found here (CI’s git):

https://raw.github.com/EllisLab/CodeIgniter/b211adee89f5fd2192051e9c0826146bd150f469/system/libraries/Session.php