2

i want to pass array in codeigniter session and want to retrieve it in another function following is my code where i pass array to session

$deliveryData = array(
                    'User_ID' => $this->input->post('User_ID'),
                    'Order_dArea' => $this->input->post('Order_dArea'),
                    'Order_dAddress' => $this->input->post('Order_dAddress'),
                    'Order_PMethod' => $this->input->post('payment_mode'),
                    'Order_dMdate' => $Order_modifieddate
                    );

            $this->session->set_userdata('deliverdata', $deliveryData);

i retrieve session in this way

$getDeliveryData = $this->session->all_userdata('deliverdata');

and i got this output

array(12) { ["session_id"]=> string(32) "d369b835203b7da7f9c27e93e6444bd2" ["ip_address"]=> string(9) "127.0.0.1" ["user_agent"]=> string(65) "Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/22.0" ["last_activity"]=> int(1372851183) ["user_data"]=> string(0) "" ["cartreturn"]=> string(1) "1" ["username"]=> string(5) "admin" ["is_loggedin"]=> int(1) ["login"]=> string(5) "aqeel" ["password"]=> string(10) "ictbeam321" ["cart_contents"]=> array(4) { ["d3d9446802a44259755d38e6d163e820"]=> array(6) { ["rowid"]=> string(32) "d3d9446802a44259755d38e6d163e820" ["id"]=> string(2) "10" ["qty"]=> string(1) "1" ["price"]=> string(4) "1200" ["name"]=> string(11) "soup item 1" ["subtotal"]=> int(1200) } ["c51ce410c124a10e0db5e4b97fc2af39"]=> array(6) { ["rowid"]=> string(32) "c51ce410c124a10e0db5e4b97fc2af39" ["id"]=> string(2) "13" ["qty"]=> string(1) "1" ["price"]=> string(4) "1400" ["name"]=> string(11) "soup item 2" ["subtotal"]=> int(1400) } ["total_items"]=> int(2) ["cart_total"]=> int(2600) } ["deliveryfee"]=> int(182) } 

now i want to get original array values so that i can use it

1

3 Answers 3

15

Try this:

<?php
    $deliveryData = array(
                'User_ID' => $this->input->post('User_ID'),
                'Order_dArea' => $this->input->post('Order_dArea'),
                'Order_dAddress' => $this->input->post('Order_dAddress'),
                'Order_PMethod' => $this->input->post('payment_mode'),
                'Order_dMdate' => $Order_modifieddate
                );
    $this->session->set_userdata('deliverdata', $deliveryData);         #to set the session with the above array

    ### for retrieving the session values ###
    $deliveryData   = $this->session->userdata('deliverdata');          #will return the whole array

    ### for retrieving any single element from the session ###
    $userid         = $this->session->userdata['deliverdata']['User_ID'];
?>
Sign up to request clarification or add additional context in comments.

Comments

0

You are getting all session data whereas you only want part of it. Rather than doing

$getDeliveryData = $this->session->all_userdata('deliverdata');

I think you just have to do

$getDeliveryData = $this->session->userdata('deliverdata');

2 Comments

i want to store array data whereas $this->session->userdata('deliverdata') store only one record can you please guide me in more detail you can get my scenario from my Q
You can store more than one value if you pass an array which you are doing. See what the result of $getDeliveryData = $this->session->userdata('deliverdata'); is
-1
//first page
$menu_records=array();
$this->session->set_userdata('logged_in', $menu_records);

//second page
var_dump($this->session->userdata['logged_in']);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.