Welcome Guest, Not a member yet? Register   Sign In
Adding session data
#1

[eluser]elmne[/eluser]
I'm trying to add session data using the Hybrid session like this

Code:
$newdata = array(
        'arrival_date' => $this->input->post('arrival_date'),
        'departure_date' => $this->input->post('departure_date')
        );
        
        $this->session->set_userdata($newdata = array(), $newval = '');

And i try to display it like this

Code:
<?php echo $this->session->userdata($arrival_date) ?>

But i get the following error message

Quote:Message: Undefined variable: arrival_date

How do i get to store information in the session then call it for display?

I created the session in the controller contructor using

Code:
$this->session->sess_create();
#2

[eluser]mi6crazyheart[/eluser]
Replace this 4th line by this...

$this->session->set_userdata($newdata = array(), $newval = '');

to this...
$this->session->set_userdata($newdata);
#3

[eluser]Clooner[/eluser]
[quote author="mi6crazyheart" date="1277288190"]Replace this 4th line by this...

$this->session->set_userdata($newdata = array(), $newval = '');

to this...
$this->session->set_userdata($newdata);[/quote]

Actually both won't work!

Saving the data
Code:
$this->session->set_userdata('some_name_to_identify', $variableyouwishtosave);

Retrieving the data
Code:
$somevariableyouwishtorestore = $this->session->userdata('some_name_to_identify');
#4

[eluser]Clooner[/eluser]
Woops, I just read you are using hybrid sessions which I am not familiair with... My code is for the build in session class...
#5

[eluser]bhogg[/eluser]
I'm not sure about the hybrid session class but should it not be this instead to retrieve?

Code:
<?php echo $this->session->userdata('arrival_date') ?>

Typically data would be inserted first with:
Code:
<?php $this->session->set_userdata('arrival_date', $value); ?>
#6

[eluser]elmne[/eluser]
Thanks, i removed
Code:
= array(), $newval = '');

when adding data to the session, i just did this

Code:
$this->session->set_userdata($newdata);
#7

[eluser]mi6crazyheart[/eluser]
@elmne
Is u'r script working right now as u wanted to... ?
#8

[eluser]elmne[/eluser]
Yes it's working.

I used something like this to add data to the session

Code:
$newdata = array(
        'arrival_date' => $this->input->post('arrival_date'),
        'departure_date' => $this->input->post('departure_date')
        );
        
        $this->session->set_userdata($newdata);

Then i use something like this to display a given session item's value

Code:
<?php echo $this->session->userdata('arrival_date') ?>




Theme © iAndrew 2016 - Forum software by © MyBB