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

[eluser]Aspi[/eluser]
Hi!

I would like get data from session.
I take session data into mysql;
Create table like this:
Code:
CREATE TABLE IF NOT EXISTS  `ci_sessions` (
session_id varchar(40) DEFAULT '0' NOT NULL,
ip_address varchar(16) DEFAULT '0' NOT NULL,
user_agent varchar(50) NOT NULL,
last_activity int(10) unsigned DEFAULT 0 NOT NULL,
user_data text DEFAULT '' NOT NULL,
PRIMARY KEY (session_id)
);
and put custom user data like this:
Code:
$newdata = array(
                   'username'  => $data['username'],
                   'roles' => $data['roles'],
                   'logged_in' => TRUE
               );

i would like get user_data->roles information

thanks for your help
#2

[eluser]virtualgadjo[/eluser]
hi,

do you serialize you user data array before inserting it into mysql and unserialize it when you retreive it before you try to get the role index ?

have swing
#3

[eluser]JuanitoDelCielo[/eluser]
Use serialize function to save it as plain text... but is it really neccesary? Why dont use a config file?
#4

[eluser]virtualgadjo[/eluser]
well actually, it's not really to save it as plain text but as a string you will be able to gat as an array again with unserialize.

The fact is, it is the usual way to store php arrays in a db... now, you could of course use only cookies as they "understand" arrays or, as i must admit i do, use native php sessions (but even it that case, if you want to use a db to store an array of values you'll have to serialize it)

hope it helps

have swing
#5

[eluser]guidorossi[/eluser]
Code:
$roles = $this->session->userdata('roles');
#6

[eluser]virtualgadjo[/eluser]
Smile well, of course, guido/sheldon is right as long as we're not speaking about retreiving from the db anymore...

have swing
#7

[eluser]InsiteFX[/eluser]
The Session library handles all serialize and unserialize but if need be you can call them alone.

InsiteFX
#8

[eluser]virtualgadjo[/eluser]
hi,
thanks for that, not being into that cooky thing a lot i must admit i haven't dug that much into the session class but maybe i should... could be handy to manage "remember me" utility...

have swing
#9

[eluser]Aspi[/eluser]
THX everybody help

i try $roles = $this->session->userdata('roles'); nothing happen
and i try $roles = $this->session->userdata('user_data'); nothing happen

if i try $roles = $this->session->userdata('session_id'); show session id

is very frustrating userdata('roles') don't return any information.

and another question is i must unserialize userdata('roles') ?

THX
#10

[eluser]virtualgadjo[/eluser]
hi

apparently, according to you first post you're using $newsdata to store your userdata array, have you tried

$this->session->newsdata('roles') ?

have swing




Theme © iAndrew 2016 - Forum software by © MyBB