Welcome Guest, Not a member yet? Register   Sign In
How to get _single_ userdata items from session database table
#1

[eluser]czesiek32[/eluser]
Hello, this is my first post Smile

I have my session stored in database, and I want to take from the table some userdata of all users, for example their id's.

It looks like this, there is a stanard db session table:

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(120) NOT NULL,
last_activity int(10) unsigned DEFAULT 0 NOT NULL,
user_data text NOT NULL,
PRIMARY KEY (session_id),
KEY `last_activity_idx` (`last_activity`)
);

The userdata field looks like this:

Code:
a:4:{s:7:"user_id";s:1:"2";s:9:"user_name";s:18:"Name Surname";s:10:"user_admin";s:3:"yes";s:19:"user_lastlogin_date";s:10:"2012-02-18";}

And I have a lot of users stored in database. Now i want to get an array of users id's - It is needed to show "who is online" after join with users table in DB.

And here is my question - how could i get this array ? Regexp ? I don't think so. I hope there is a way to get all userdata fields but not looking like s**t (a:4:{s:7:"user_id";s:1:"2";s:9:"user_name";s:18:"Name Surname";s:10:"user_admin";s:3:"yes";s:19:"user_lastlogin_date";s:10:"2012-02-18";}) but like variables ($user_id=2, $user_name="Name Surname") and so on.

I hope you can understand what i mean, thanks for any help.


Messages In This Thread
How to get _single_ userdata items from session database table - by El Forum - 02-19-2012, 04:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB