Codeigniter 会话在重定向后销毁 [英] Codeigniter session destroy after redirect

查看:53
本文介绍了Codeigniter 会话在重定向后销毁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在会话中添加订单 ID 和购物车项目.如果我在会话中添加 2 个购物车项目.它工作正常.如果我在会话中添加 3 个或更多购物车项目.重定向后的所有数据丢失.控制器的名称是 checkout.

function pay_order($order_id){$this->load->helper('url');$this->load->library('session');$this->load->library('cart');$this->load->helper('url');$this->load->helper('form');$output = $this->cart->contents();$output = $this->sort_array($output);$list['data'] = $output;$list['order_id'] = $order_id;$this->session->set_userdata('ses', $list);echo '

重定向前的会话';print_r($this->session->userdata('ses'));//所有数据都存在.重定向('结帐/do_payment');}函数 do_payment(){$this->load->helper('url');$this->load->helper('url');$this->load->library('session');$this->load->library('cart');$this->load->helper('url');$this->load->helper('form');$this->load->library('session');$this->load->model('customer_model');echo '重定向后

';print_r($this->session->userdata('ses'));//这里没有得到任何数据.}

还附加了重定向前的快照.

解决方案

你的配置是什么应用程序/配置/config.php

如果是$config['sess_use_database'] = FALSE;

这意味着您将会话信息存储在 cookie 中,限制为 4kb.大概这就是问题所在.在数据库中存储大量数据.

http://ellislab.com/codeigniter/user-guide/libraries/session.html

I am adding order id and cart items in session. if I add 2 cart items in session. It's works fine. If I add 3 or more items of cart in session. All the data after redirect lost. the name of controller is checkout.

function pay_order($order_id){
    $this->load->helper('url');
    $this->load->library('session');
    $this->load->library('cart');
    $this->load->helper('url');
    $this->load->helper('form');
    $output = $this->cart->contents();
    $output = $this->sort_array($output);
    $list['data'] = $output;
    $list['order_id'] = $order_id;
    $this->session->set_userdata('ses', $list);
    echo '<pre> Session Before Redirect';
    print_r($this->session->userdata('ses'));// all data present.
    redirect('checkout/do_payment');
}
function do_payment(){
    $this->load->helper('url');
    $this->load->helper('url');
    $this->load->library('session');
    $this->load->library('cart');
    $this->load->helper('url');
    $this->load->helper('form');

    $this->load->library('session');
    $this->load->model('customer_model');


    echo 'After redirect<pre>';
    print_r($this->session->userdata('ses'));// does not get any data here.
 }

snapshot before redirect is also attached.

解决方案

What is your configuration in application/config/config.php

If it is $config['sess_use_database'] = FALSE;

that means that you store session info in cookies, which is limited to 4kb. Probably that is the problem. Store large amount of data in database.

http://ellislab.com/codeigniter/user-guide/libraries/sessions.html

这篇关于Codeigniter 会话在重定向后销毁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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