Sessions: 'ci_sessions' user_data - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Sessions: 'ci_sessions' user_data (/showthread.php?tid=20662) |
Sessions: 'ci_sessions' user_data - El Forum - 07-17-2009 [eluser]lorem_ipsum_dolor_sit[/eluser] Hi all, I was very happy to see CI had built in session handling and that it would save all the data to a database. I only have one problem, The user_data column of the database is a bit unclear to me. In the database I get: Code: a:3:{s:2:"id";s:1:"1";s:8:"username";s:6:"lorem_ipsum";s:9:"logged_in";s:1:"1";} Is there an easy way to convert this to an array or something similar? Thanks Sessions: 'ci_sessions' user_data - El Forum - 07-17-2009 [eluser]Dam1an[/eluser] You don't need to worry about converting this to an array, every time the session class is initiated, it will take that data and de-serialize it into an array, which you then access as normal Sessions: 'ci_sessions' user_data - El Forum - 07-17-2009 [eluser]lorem_ipsum_dolor_sit[/eluser] I want to run a query on the session data in the database to see who is currently logged in though? Or is there another way of doing that which I am completely missing? Sessions: 'ci_sessions' user_data - El Forum - 07-17-2009 [eluser]Dam1an[/eluser] Ah, this is something which has been discussed a few times in the forum Basically you want to track the last_activity of a user which gets updated on every page request for that user. You could either extend the session table to have this or in the users table (or make a seperate table for this). Then when you need to find users currently online, just find the ones which have a recent_activity in the last X minutes. If you need some more info just search the forums for some similar threads Sessions: 'ci_sessions' user_data - El Forum - 07-17-2009 [eluser]lorem_ipsum_dolor_sit[/eluser] Right so I did some searching and I came up with this with the help of Phil Sturgeon's suggestion on another thread. I had to modify it because the regular expression he suggested wasn't working.. It is a simple solution, I'm sure there is a better one but I wasn't keen on setting up a table for online users when I already had the information I needed in the database. Code: // $user_data should be the user_data column of a row in the session table Hope that this helps someone.. Sessions: 'ci_sessions' user_data - El Forum - 09-09-2009 [eluser]spmckee[/eluser] Thanks for the tip maxnov but I'm not sure how you are pulling in the $regex_logged_in, $regs, and $regex_username variables. $regex_logged_in is defined but not used. $regex_username and $regs are used but not defined. Any ideas? Thanks! |