Sessions Management PHP Class 1.0.1

Monday, September 11, 2006
,

A new version of the Sessions Management PHP Class has been released. Read further to see what is new in this version of the script.

What's new in this version:

  • in the 'session_data' table, the 'session_id' field is now a primary key and it's type is changed from varchar(255) to varchar(32). previously a whole table scan was done every time a session was loaded - thanks Harry
  • added a new "stop()" method which unsets a session's variables and deletes it from the database. this is due to the fact that some people were using the private "destroy" method which is not to use for this purpose
  • you can now override the default settings of session.gc_maxlifetime, session.gc_probability and session.gc_divisor configuration options
  • on popular request, an example file was added

4 comments:

  1. cris said...

    Hi
    I've tried your class but i've got a question: how can you do to recover data in the session_data row?

    I've create a function to get all connected user in my website and i want to get the data from session_data.

    For ex:
    $_SESSION[page][var1]='test';
    $_SESSION[page][var2]='test2';
    ...

    I've tried with an unserialize and also with session_decode but no way...

    Can you help me?

  2. Stefan Gabos said...

    so many people got it all wrong! and you are one of them :)

    as the documentation says: "after instantiating the class, use sessions as you would normally"

    everything is ok with adding data to the session as you described here:

    $_SESSION[page][var1]='test';
    $_SESSION[page][var2]='test2';

    that would put the data in the session. you have to ignore the fact that the data is stored in a database. that's transparent to you. you just use sessions as you would normally.

    With

    $_SESSION[page][var1]='test';
    $_SESSION[page][var2]='test2';

    you add the data to your session.

    Now go ahead and print_r($_SESSION) and you'll see that the data is in the session. Try and print_r($_SESSION[page][var1]) and you'll get 'test'!

  3. cris said...

    this is not the problem, the problem is to get all data from all user on the website, it is not possible to get $_SESSION from an other visitor than me.

    I've find the solution with this code:
    function unserializesession($data) {
    $vars=preg_split('/([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\|/',$data,-1,PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
    for($i=0; $vars[$i]; $i++)
    {
    $result[$vars[$i++]]=unserialize($vars[$i]);
    }
    return $result;
    }

  4. Stefan Gabos said...

    oh, i understand. yeah, i found the code too in the php manual but does it work if the SESSION data contains the "|" character?

Post a Comment

GlossyBlue Blogger by Black Quanta. Theme & Icons by N.Design Studio
Entries RSS Comments RSS