Re: HTTP_Session using DB
| From: | Torsten Roehr | Date: | Fri, 08 Apr 2005 10:38:56 +0000 |
| Subject: | Re: HTTP_Session using DB | ||
| References: | 1 2 3 4 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-18643@lists.php.net to get a copy of this message | ||
"Dan Rossi" <pear@electroteque.org> wrote in message
news:97e9d921659d34c1e9fdf1bd71ca2a6e@electroteque.org...
>
> On 07/04/2005, at 11:28 PM, Torsten Roehr wrote:
> >
> > Hi Dan,
> >
> > I've been using HTTP_Session with the DB container (MySQL) in lots of
> > projects like this:
> > HTTP_Session::useCookies(false);
> > HTTP_Session::setContainer('DB', array('dsn' => $dsn,
> > 'table' =>
> > TABLE_SESSIONS, 'autooptimize' => true));
> > HTTP_Session::start(SESSION_NAME);
> > HTTP_Session::setExpire(SESSION_LIFETIME);
> >
> > Most times combined with LiveUser (read: let LiveUser do the
> > idle/expire
> > checks). It even works with session_regenerate_id().
> >
> > One thing to look out for is that the value for
> > HTTP_Session::setExpire()
> > should not be 0 - this doesn't seem to work.
> >
> > What kind of problem do you have?
>
> I'm not the one with problems ? :) How can you get HTTP_Session to do
> the session handling for LiveUser ?
Sorry Dan, of course I meant "Rob".
Just include all the lines from above at the top of all your files (like you
do with the LiveUser init call). LiveUser is not doing more than calling
session_start() and session_destroy() at the appropriate time. So
HTTP_Session just works as the container because it registers its methods as
the session_save_handlers and so on.
You might get a warning "session already started at ..." when LiveUser makes
its session_start() call. Just outcomment this line and all is fine. For
HTTP_Session::setExpire() you should use a bigger value than for LiveUser's
expire so that LiveUser will "react" before HTTP_Session. LU gives you more
control over what to do in case of idled or expired.
I've been doing it this way in numerous projects. Works like a charm. Just
give it a try.
Hope this helps!
Best regards, Torsten