On 1/1/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hi all,
> I want to give users the ability to set their own expire times. Problem is
> that I'm not tapping the database for their choice until after
> cgiapp_init, the only place I can really:
>
>    $self->session_config( DEFAULT_EXPIRY => 15);
>
> without getting an error and death.
>
> I'd like to be able to (re)set the expiration time later. Anyway to do
> this? (I'm not using cookies, other than the one made by default by
> C::A::P::Session).)

There are four options that come to mind.

1. You can call 'session_config' at anytime throughout the request, as
long as you do not call 'session' beforehand.  As soon as you call
$self->session, you can no longer call $self->session_config without
getting an error, as the Session object has already been created.  So
make sure that you do not call 'session' until you know you have
called 'session_config'.

2.  Set the cookie manually instead of letting CAP::Session do it for
you.  Just add the SEND_COOKIE => 0 option to your session_config
call, and a cookie will not be sent for you.  Then in a postrun
handler you can figure out what to set the timeout to, and set the
cookie manually (you can look at the CAP::Session source to see how to
set a cookie properly).  You can also change the session timeout in
CGI::Session at the same time by calling $self->session->expires with
a new expiry value.

3. Set your sessions to last for a really long time (or the max
allowed session time that you allow), and then place your 'floating'
time out in an actual session variable.  Then at the cgiapp_init
stage, check this session variable to see if the session should be
expired and delete it if it is (or just clear the parameters in the
session, since most likely a new session will be created for this
user).

4. Let CGI::Session do the timeouts for you on a per parameter basis. 
If you check the documentation for CGI::Session, you will note that
you can set a custom timeout for each individual parameter.  You can
change this timeout at any time you like.  This will not affect the
cookie timeout at all which will stay at the original value (which
should be the max allowed timeout), but when you ask for a session
varaible, CGI::Session will check to see if this session variable is
still fresh and clear it if it is expired.  If you don't want to do
this for all of your individual session variables, then just place all
session information in a hashref and stick that in the session and set
the expiry on that one value.

Personally, I would probably go with number 4 as it would be the
easiest to implement...

Cheers,

Cees

---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/[email protected]/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to