0
votes

I know this question has been asked before but my session array is set up different and i would liuke to be able to echo out 'firstname', and 'email' in my members view.

Here is what my session array looks like:

Array
(
    [session_id] => 0be663ae77530e5992d3116af24a216d
    [ip_address] => 
    [user_agent] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36
    [last_activity] => 1421547754
    [user_data] => 
    [email] => Array
        (
            [firstname] => Travis
            [email] => [email protected]
            [password] => 894027e71b85d60bcc5b0dbe6e83f1f6
        )

    [is_logged_in] => 1
    [firstname] => 
)

I want to get to the email array and echo out the firstname. any help would be greatly appreciated, thank you.

this is my function that sets the userdata. if you see a better way of doing it please by all means share, i would be very greatfull. public function register_user($key){

$this->load->model('model_users');
        if($this->model_users->is_key_valid($key)){
            if($newemail = $this->model_users->add_user($key)){
                $data = array(
                    'firstname' => $this->input->post('firstname'),
                    'email' =>  $newemail,
                    'is_logged_in' => 1
                );
                $this->session->set_userdata($data);
                redirect('login/members');
            }else echo "Failed to add user, please try again.";
        }else echo "invalid Key";
    }
2

2 Answers

3
votes

The easiest way I can think to access it would be this:

$email = $this->session->userdata('email');

Then you can echo the info inside of it with:

echo $email['firstname'];

and

echo $email['email'];

From what I can see, CodeIgniter's session library doesn't have any direct ways to access multidimensional array values.

0
votes
echo 'firstname: ' . $_SESSION ['email']['firstname'];
echo 'email: ' . $_SESSION ['email']['email'];