Muhammad Danish
Muhammad Danish

Reputation: 109

Codeigniter session destroy after redirect

enter image description here

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.

Upvotes: 3

Views: 13685

Answers (5)

pollux1er
pollux1er

Reputation: 5921

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']);

Upvotes: 0

Anjani Barnwal
Anjani Barnwal

Reputation: 1522

it's may be a php/codeigniter version issue please use lower version of php like 5.3 or upgrade your codeigniter version, your problem will be solved.

Upvotes: 0

Ahmad Dehnavi
Ahmad Dehnavi

Reputation: 1543

I have the same problem and solve it by disable check for session user agent:

 $config['sess_match_useragent']=FALSE

Upvotes: 1

Milan Zavišić
Milan Zavišić

Reputation: 301

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

Upvotes: 4

user2092317
user2092317

Reputation: 3338

please remove the following line and try

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

Upvotes: 1

Related Questions