简体   繁体   English

Codeigniter 会话在重定向后销毁

[英]Codeigniter session destroy after redirect

在此处输入图片说明

I am adding order id and cart items in session.我正在会话中添加订单 ID 和购物车项目。 if I add 2 cart items in session.如果我在会话中添加 2 个购物车项目。 It's works fine.它工作正常。 If I add 3 or more items of cart in session.如果我在会话中添加 3 个或更多购物车项目。 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你在 application/config/config.php 中的配置是什么

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

that means that you store session info in cookies, which is limited to 4kb.这意味着您将会话信息存储在 cookie 中,限制为 4kb。 Probably that is the problem.大概这就是问题所在。 Store large amount of data in database.在数据库中存储大量数据。

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

请删除以下行并尝试

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

我有同样的问题并通过禁用检查会话用户代理来解决它:

 $config['sess_match_useragent']=FALSE

这可能是 php/codeigniter 版本问题,请使用较低版本的 php,如 5.3 或升级您的 codeigniter 版本,您的问题将得到解决。

I solved this issue by updating the session writting and reading in codeigniter code session manager.我通过更新 codeigniter 代码会话管理器中的会话写入和读取解决了这个问题。

system/libraries/Session/session.php

Go to line 281转到第 281 行

ini_set('session.name', $params['cookie_name']); 

Replace session.name by session.id用 session.id 替换 session.name

ini_set('session.id', $params['cookie_name']);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM