in reply to Re^4: CGI::Session - non-stop session creation problem
in thread CGI::Session - non-stop session creation problem

Ok, I think I know what you mean now. You want something like this (doesn't work because CGI::Session doesn't support it):

$session = CGI::Session->new(undef, $sid, {Directory=>'C:/apache/sessi +ons',NoCreateIfNotExists=>1});
I'm not entirely clear on the architecture of CGI::Session, but that may need to go into the DSN instead. Anyway, once you tell it not to autocreate new sessions, the code would have to change to honour it.

Another alternative, which I just stumbled upon. Which you may not like for similar reasons as before. I suspect this is how the author of CGI::Session envisions doing what you ask for:

my $sid = $foo->cookie('main') || undef; my $session; # = undef if (defined $sid) { $session = CGI::Session->new(undef, $sid, {Directory => 'c:/apache/s +essions'}); $session->delete() if $session->is_new(); }
When you get the session, you can check if it's a new session or not. If it is, you can delete it. From what I can tell reading the code, this won't hit your hard disk at all. And the fact that the is_new sub is there at all says to me that this is the author's idea of solving this very problem.

Replies are listed 'Best First'.
Re^6: CGI::Session - non-stop session creation problem
by ikegami (Patriarch) on Apr 08, 2005 at 05:58 UTC
    One can't call delete on a session that was never saved (flushed), as discussed in this thread. Follow the link for a working solution.
Re^6: CGI::Session - non-stop session creation problem
by Stenyj (Beadle) on Apr 07, 2005 at 22:28 UTC
    That appears to be exactly what I'm looking for.
    Will test it shortly, and see how it goes.

    Thx for all the help!