问题
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.
回答1:
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
回答2:
please remove the following line and try
$this->load->model('customer_model');
回答3:
I have the same problem and solve it by disable check for session user agent:
$config['sess_match_useragent']=FALSE
回答4:
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.
回答5:
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']);
来源:https://stackoverflow.com/questions/19105321/codeigniter-session-destroy-after-redirect