• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to display the blob data of table ci_sessions : resolved :)

With CI3, we can manage session variables with database, creating a table like this
       `id` varchar(40) NOT NULL,
       `ip_address` varchar(45) NOT NULL,
       `timestamp` int(10) unsigned DEFAULT 0 NOT NULL,
       `data` blob NOT NULL,
       PRIMARY KEY (id),
       KEY `ci_sessions_timestamp` (`timestamp`)
In documentation, we are column 'data' with type is BLOB.

How do you do to read this data in order to get information session ? It's not a serialize variable or json_encode.


I believe it's just storing the actual $_SESSION data in the native format for $_SESSION. Like if you used the filedriver for sessions and looked in the dir that the session data is stored, and viewed one of the session files.

I haven't tried it but you might be able to just use session_decode($session_data_string):

However that will take the data passed in $session_data_string and use it to automatically populate the $_SESSION superglobal instead of returning it, so may not be what you're wanting, but there are other user comment solutions on that page that may be useful.

Thanks you but like you say, i try with session_decode but it's not the result that i'm wanting because in database, the string in column data is like "__ci_last_generate:i (int) | ... " and the format is not a serialize data or session encode.
I try with the diffrent header (header('Content-Type: ..')) but no result.
I want to use these datas in my administration interface to see who is connected and manage session users.

To solve my problem, I make a function to explode and after implode this datas in order to have an array like $t[key] = $value.
Also, i create a library to manage array especially for managing non-existing keys because of the format string present in database.

For everybody, if you use by example session variable with hour (or other) like this format "hh:mm: ss" (or using ":").
If you want to use it via session variables present in column 'data' of the table 'ci_sessions' (or other name you give it) in database, change the format especially if you made a function like me, because of the ":" in the format string in column 'data'.

i resolved my problem
PHP Code:
// you retrieve your dat in ci_sesion_ table of the database y a request 
// .....

$session_data $row->data ;  // your BLOB data who are a String

$return_data = array();  // array where you put your "BLOB" resolved data
$offset 0;
   while (
$offset strlen($session_data)) 
       if (!
strstr(substr($session_data$offset), "|")) 
          throw new 
Exception("invalid data, remaining: " substr($session_data$offset));
$pos strpos($session_data"|"$offset);
$num $pos $offset;
$varname substr($session_data$offset$num);
$offset += $num 1;
$data unserialize(substr($session_data$offset));
$return_data[$varname] = $data;  
$offset += strlen(serialize($data));

// in $return_data your will have your datas and can access to its ! :) 

That's a horrible, really horrible solution. You should not ever need to decode another user's session data; I suggest you find another way to achieve whatever it is that you're trying to do.

Ok.. but what the utility to use blob data for sessions (in database) if you never use them to check what you want ?
How do you do or suggest please ?

A session is intended to store a relatively limited amount of data for a specific user, usually for a limited amount of time. That data is only intended to be used by that user. One of the reasons a person might choose to store session information in the database is that they have limited control over portions of the file system in which they could securely store this data. Another would be that they may need to share the sessions between multiple servers.

Sessions are really just meant to be a low-level system to support short-term persistence of data for the site, and aren't really intended to be exposed to the users of the site. If you want data to be available to other users on the site, such as administrators, you should store it in other tables in the database. In most cases, it's better to relate long-term data about users to a longer-lived ID, like a user ID.

If you really have some compelling need to relate data to sessions for users other than the user of that session, you should build a reference table to relate the session IDs to other IDs in the system. I would recommend just inserting the reference data during login or some similar process, then maybe adding a routine to remove old data every so often or cleaning it up while generating whatever reports need the data.

I ran into the same problem, and narf said the same thing to me, lol...

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.