I try to create realtime monitoring user using session database.
I've can unserialize ci_sessions in codeigniter 2.x.x, but in Codeigniter 3.x.x I can't. After I use var_dump there is defferent format, like this
(04-10-2015, 03:45 AM)InsiteFX Wrote: In CI 3.0 it doe's not look like they are using the unserialize and serialize methods anymore.
Best to look at the session class to see what's going on.
I try to looking CI_Session_database_driver.php, and I found Serialized session data
But I still don't understand
I've poor skill of PHP
PHP Code:
/** * Read * * Reads session data and acquires a lock * * @param string $session_id Session ID * @return string Serialized session data */ public function read($session_id) { if ($this->_get_lock($session_id) !== FALSE) { // Needed by write() to detect session_regenerate_id() calls $this->_session_id = $session_id;
// PostgreSQL's variant of a BLOB datatype is Bytea, which is a // PITA to work with, so we use base64-encoded data in a TEXT // field instead. $result = ($this->_platform === 'postgre') ? base64_decode(rtrim($result->data)) : $result->data;
/** * Write * * Writes (create / update) session data * * @param string $session_id Session ID * @param string $session_data Serialized session data * @return bool */ public function write($session_id, $session_data) { // Was the ID regenerated? if ($session_id !== $this->_session_id) { if ( ! $this->_release_lock() OR ! $this->_get_lock($session_id)) { return FALSE; }
I tried your example, but you get all the users!
My question is: is there a way to list only the active users (the users who are online) and exclude the expired sessions.
Thanks.
You can sometimes come across this issue if you are using different versions of PHP, or if you change the version of PHP you are using while a session was open.
For example if you have a session cookie with an app that uses PHP 5.6.* and then you try to use it with an app (that resides on another sub-domain) that uses PHP 7.2.*, then you are going to get a warning error. Or, if you had an open session and then you changed the version of PHP that you are using with your app (say if you are developing locally and switching around PHP versions), then you'll get the warning. So best to use serialize/unserialize and with PHP version that does not change.