Please forgive me for this stupid question, but I'm hoping for some insight on how some of you more experienced programmers use CGI::Session.

I'm currently using this in my scripts:
my $sid = $foo->cookie('main') || undef; my $session = new CGI::Session(undef, $sid, {Directory=>'c:/apache/ses +sions'});

When a user logged in, the session ID was stored in the cookie 'main'. I'm encountering a few problems though. Many of my pages are used by users both logged in and not logged in. I want to use sessions for those logged in, but NOT create a session for those who aren't.

I was using:
if ($sid) { $session = new CGI::Session(undef, $sid, {Directory=>'c:/apache/se +ssions'}); # a bunch of code that grabbed data from the session }

The problem here is that $sid could exists, even if the sessions has expired but the cookie hasn't (for whatever reason that may happen), resulting in a new session being created every single time the page is loaded. The last thing I need is thousands of session files being generated for no good reason ;-p

So I'm *guessing* that there's some variation of this line:
$session = new CGI::Session(undef, $sid, {Directory=>'c:/apache/sessions'});

where it won't create a new session if it doesn't exist, or something of that sort.

The 3 tutorials that I've printed and previously used for reference don't seem to address this problem.

Can anyone bail me out here?

Any help/advice/suggestions would be greatly appreciate.

Thx,

Stenyj

In reply to CGI::Session - non-stop session creation problem by Stenyj

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.