Is there a way to read respectively parse Joomla session data in PHP as session_decode() and unserialize() are not working on that values?

In my component I need to read data from all active non-guest sessions (data column in the #__session database table) and check for the existence of certain variables.

1 Answer 1


In that field data is split into namespaces. Namespace and its data is separated by |, so if you use explode('|',$data) you will achieve array where odd index element is an data array and each even index element is an namespace. Here is an example how to decode this variable into namespaces:

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$raw_data = str_replace('\0\0\0', chr(0) . '*' . chr(0), (string)$db->loadObject()->data);
$raw_data = explode('|',$raw_data);

$data = array();
for( $idx = 1, $ic=count($raw_data); $idx<$ic; $idx+=2 ) {
    $data[$raw_data[$idx-1]] = unserialize($raw_data[$idx]);

The $data variable will contain session data split into separate array elements where array key is namespace. The default namespace should be first and its index should be __default

  • Excellent solution! Your code snippet was working right away with Joomla! 3.4.3 Stable. Aug 13, 2015 at 9:30
  • Should, I tested it on Joomla 3.4.3, of course this is for single session element. If you want to check all sessions you will need to change it a little bit. Probably create a function from this and use it on every session element. Also remember that if you have many sessions trying to parse all will have huge performance downfall. Aug 13, 2015 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.