session handler class
| From: | scott [gts] | Date: | Mon, 02 Jul 2001 19:32:14 +0000 |
| Subject: | session handler class | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-55887@lists.php.net to get a copy of this message | ||
in regards ot the "OO v. Functions", where you asked about
a session handler class... i have written a class that handles
sessions, although i dont know if it's exactly what you're
looking for, you might want to give it a peek.
since i am a big fan of code reuse, i must include my
DB abstraction "db.php" and error handler code "main.php",
becuase the session class relys on functions contained in
those two files.
i have taken a different view on the idea of handling
sessions... the session handler is simple, yet powerful.
there's no registering of global variables or any
of that nonsense. there's a simple assoc. array that
holds all of the data of the session, which, IMO, is a
much more sensible way to store/retrieve information
than using global variables.
having all your session data concentrated into the
$session->data[] array makes things neat and elegant IMO.
I am still making updates to the session class.
currently, there's no way to specifically end a session
other than "undef $session"... i am going to add support
for auto-saving information when the $session class
is destroyed, and a few other bells-and-whistles to
make it even easier to use.
//to start up the session:
// init_session is a wrapper function that sets up
// the session properly (looks for a valid 'sid' cookie)
$session = init_session();
// $session is now an object.
// to set a 'session' variable:
$session->data['something'] = "someone"
// to count how many times this session was loaded
$session->data['counter']++;
// to save the $session->data[] array to the DB
$session->UpdateData();
// and if you use authentication on your site, and want
// to quickly remember a user's name, you can attach a
// username to the session with:
$session->RegisterName('scott');
basically, put these all in the same dir, and run test.php
> -----Original Message-----
> From: Aral Balkan [mailto:aral@aralbalkan.com]
> Subject: [PHP] OO v. Functions Was: Re: [PHP] PHP Form (aka:Re: [PHP]
> Can any one spot the Parse error Here)
>
> Although I guess there are times when you
> can't use classes in PHP (has anyone been able to create a custom session
> handler *class*, for example?.. how would you set up the
> session_set_save_handler that takes strings to point to the various handler
> functions from within a class?)