CodeignitEr会话不与AJAX一起使用

编程入门 行业动态 更新时间:2024-10-27 07:22:18
本文介绍了CodeignitEr会话不与AJAX一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

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

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

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

任何帮助将不胜感激。

解决方案

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

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

raw.github/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):

raw.github/EllisLab/CodeIgniter/b211adee89f5fd2192051e9c0826146bd150f469/system/libraries/Session.php

更多推荐

CodeignitEr会话不与AJAX一起使用

本文发布于:2023-11-17 03:46:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608709.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不与   CodeignitEr   AJAX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!