[horde] Re: horde sessionhandler

Andrew Morgan morgan at orst.edu
Thu Apr 21 16:42:43 PDT 2005


On Thu, 21 Apr 2005, Kevin Konowalec wrote:

> On Apr 21, 2005, at 11:49 AM, Andrew Morgan wrote:
>
>> On Thu, 21 Apr 2005, Kevin Konowalec wrote:
>> 
>>> Is it possible to use an external script to do a data dump (just so I
>>> can get an idea of what's in the session data variable without mucking
>>> with horde code)?  I'm using mySQL for my session handler container.
>> 
>> Sure.  Make a simple php script that connects to MySQL and selects one or 
>> more of the rows from the sessions table.  Unserialize() it and var_dump() 
>> it.
>> 
>> No need to try to do this using the Horde code.
>> 
>> 	Andy
>> 
>
> Hey Andy!
>
> So this is what I tried:
>
> <?php
>        require_once('DB.php');
>        $db=DB::connect("mysql://myuser:mypass@myserver/horde");
>        if (DB::iserror($db)) {
>                die($db->getMessage());
>        }
>
>        $sql = "SELECT *
>                FROM horde_sessionhandler
>                WHERE session_data like '%konowal%'";
>
>        $qq = $db->query($sql);
>
>        $row = $qq->fetchRow();
>        if (DB::isError($row)) {
>                die ($row->getMessage());
>        }
>
>        $kk = $row[2];
>        echo "{$kk}";
>        $str = unserialize($kk);
>
>        var_dump($str);
> ?>
>
>
> It returns my login session variable in $kk but then:
>
> PHP Notice:  unserialize(): Error at offset 0 of 25357 bytes in 
> /tmp/test.html on line 24
> bool(false)
>
>
> Any thoughts?

I ran into the same problem when I actually tried to do this myself.  :)

I ended up writing the following code (the function came from php.net):


<?php

$dbh = mysql_connect('host', 'user', 'pass');
mysql_select_db('horde', $dbh);

$sql = "SELECT * FROM horde_sessionhandler";

$result = mysql_query($sql);

$r = mysql_fetch_row($result);

$str = unserializesession($r[2]);

echo "<pre>\n";
print_r($str);
echo "</pre>\n";


function unserializesession($data) {
         $vars = preg_split('/([a-z,A-Z_]+)\|/', $data, -1,
                         PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
         for($i = 0; $vars[$i]; $i++) {
                 $result[$vars[$i++]] = unserialize($vars[$i]);
         }
         return $result;
}

?>



Obviously, this only returns the first row in the session table. 
Depending on what information you want from the session table, you can run 
the query in a while() loop to fetch it all.

 	Andy


More information about the horde mailing list