不能在codeIgniter上使用会话 [英] can't use session at codeIgniter

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

问题描述

我的表单控制器中有一个会话,该会话是在用户保存
时创建的,该会话会影响表单页面,所以我的问题是:

I have a session in my form controller the session is create when the user save the session affect the form page so my problem is :

如果我加载页面时没有点击保存未定义的索引[会话索引],出现了错误

if I loaded the page without clicking on save a undefined index[session index] error appears

所以我在主页
上创建了会话,但是问题是我首先不访问主页就加载了表单页面,但未定义的索引错误出现了
我试图调用方法 session_start(),但出现了此错误
遇到PHP错误

so I created the session at the home page but the problem is if I loaded the form page without visiting the home page at first the undefined index error appear I tried to call the method session_start() but I got this error A PHP Error was encountered


严重性:通知消息:会话已开始-
忽略session_start()文件名:views / Form.php行号:5

Severity: Notice Message: A session had already been started - ignoring session_start() Filename: views/Form.php Line Number: 5


推荐答案

我强烈建议使用默认CI会话库。您可以在 autoload.php 中自动加载会话。您的会话将自动开始,无需调用 session_start()

I strongly recommend using the default CI session library. You can autoload the session in autoload.php. Your session will start automatically, there is no need to call session_start().

然后替换 $ _ SESSION ['save'] = true $ this-> session-> set_userdata('save','true');

我认为您需要检查 session ['save'] 是否为真,因此在默认情况下,您必须默认声明 session ['save'] 为默认值 false 是在routes.php中指定的,还要确保在表单页面控制器中已经定义了 session ['save'] 索引,检查如下:

I think you need to check if session['save'] is true or not, so beforehand you must declare by default that session['save'] is "false" in the default controller which is specified in the routes.php, and also make sure the session['save'] index is already defined in your form page controller, check like this:

if ($this->session->userdata('save')) {
     // do something when exist
} else {
    $this->session->set_userdata('save', 'false');
}

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

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