简体   繁体   中英

Codeigniter session destroy after redirect

在此处输入图片说明

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

请删除以下行并尝试

 $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.

system/libraries/Session/session.php

Go to line 281

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

Replace session.name by session.id

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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