CodeignitEr会话不与AJAX一起使用 [英] CodeignitEr Session not working with AJAX

查看:127
本文介绍了CodeignitEr会话不与AJAX一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的问题是我试图通过ajax登录我的系统。让我解释一下你的第一个。



当我的用户放入他的登录详细信息,它将通过Ajax请求发送到服务器,然后一旦它得到验证,我创建一个进入会话并保存诸如userid和logged_in标志之类的信息。



然后我通过Json将这些值返回给用户,这是通过一个javascript和重定向



如果用户未通过身份验证,则会显示错误。



这是。当我创建一个会话变量,当用户被重定向到仪表板。有时它不创建会话变量,为什么我不能显示退出按钮?



任何帮助将不胜感激。

解决方案

如果您使用了基于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

这篇关于CodeignitEr会话不与AJAX一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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