Welcome Guest, Not a member yet? Register   Sign In
CI Sessions user_data
#1

[eluser]CI_Newb[/eluser]
How can I extract certain values from the user_data stored in my ci_sessions table.

Nothings been modified, using standard CI sessions.

I check the user_data field and it has this in it.
Code:
a:48:{s:8:"first_name";s:7:"John";s:12:"is_logged_in";s:1:"1";s:8:"password";s:32:"ce71163405f42e7fae2fe4330873021";s:13:"email_address";s:25:"[email protected]";}

Say I want to echo just the email_address. How can I do that?
#2

[eluser]bretticus[/eluser]
The strings you have in your session database records have been serialized. Using PHP's unserialize function, you can turn that string back into a variable. Notice the beginnging of the string:

Quote:a:48:{s:8:"first_name";s:7:"J...

That a stands for array. This means that when you unserialize it, you will end up with an array variable.

That means to get your email value, this code should be pretty close to what you need:

Code:
$session_data = unserialize($session_record_string);
echo $session_data['email_address'];
#3

[eluser]CI_Newb[/eluser]
Thank you very much for explaining this, very good to know Smile
#4

[eluser]WanWizard[/eluser]
You shouldn't access that data directly, that's what the session library methods are for
Code:
echo $this->session->userdata('email_address');
#5

[eluser]bretticus[/eluser]
Agreed @WanWizard. I assumed (and perhaps incorrectly) that he wanted to pull emails out arbitrary for batch processing or some other purpose since he was looking at database session data in the first place. Calling
Code:
echo $this->session->userdata('email_address');
will get the email, but only for the user that is currently logged in.
#6

[eluser]CI_Newb[/eluser]
I understand completely what you guys are saying and I do use that for logged in users, but what i'm doing is accessing the user_data from all users currently logged in, no only myself.




Theme © iAndrew 2016 - Forum software by © MyBB