Muhammad Danish
Muhammad Danish

Reputation: 109

After redirect session lost in codeigniter

The session value lost after the redirect. I m redirecting from pay_order method to do_payment method. when I print the session value in do_payment method its return false. just simple calling the do_payment method display the session value. Please help what is the problem with redirect..?

function pay_order($order_id)

{
                 $this->load->helper('url'); //loading url helper    
                 $this->load->library('session');//loading session lib
                 $this->load->library('cart'); //loading cart lib
                 $this->load->helper('form');//loading form helper
                 $output = $this->cart->contents();// getting data from cart.
                 $output = $this->sort_array($output);// sorting the array
                 $list['data'] = $output;
                 $list['order_id'] = $order_id;
                 $this->session->set_userdata('abc', $list);// setting the session
                 redirect('checkout/do_payment'); // redirecting to do_payment

    }
    function do_payment() 
    {

             $this->load->helper('url'); //loading url helper
             $this->load->library('session'); //loading session library
             $arr = $this->session->userdata('abc');// getting session data in $arr
             var_dump( $arr );// return false value.
             //$this->load->view('order/pay_through_gateway');
    }

when I redirect from pay_order method the session is not available in do_payment method. why?

Upvotes: 0

Views: 1938

Answers (2)

ritesh
ritesh

Reputation: 2265

There is a problem, check the line in the method pay_order() where you are setting the session.

$list['order_id'] = $order_id
$this->session->set_userdata('abc', $list);// setting the session

Before that line you have missed semicolon. And everything looks fine.

Update:

There is no error as I think, check whether you may have null value while you are storing the values in session. And check the values by following code in do_payment() method.

function do_payment(){
    $this->load->library('session'); //loading session library
    $arr = $this->session->userdata('abc');// getting session data in $arr
    print_r( $arr );// print the $arr content
}

Upvotes: 1

Jlil
Jlil

Reputation: 170

Change this:

$list['order_id'] = $order_id

To this:

$list['order_id'] = $order_id;

You have a semicolon missing. You do not see any errors because of the redirection.

Upvotes: 0

Related Questions