Hope this isn't a duplication of effort, but I'm learning this myself and it's a good exercise for me to work it out (plus it's a slow day at work).

Here's how I would do it (untested). Constructive crits of my implementation welcome.

#! /Perl use strict; use warnings; use lib '.'; # perhap needed if using IIS on NT/W +in2K use CGI qw(:standard remote_addr); my $unique = $ENV{'REMOTE_ADDR'}; # caution: forgable $unique =~ s/\./_/g; my ($expired) = 0; tie my $session, "session_track", "C:/TEMP/$unique.txt"; &login if (defined($login)); # assuming $login is passed as a par +am &check_timeout; # call this in all programs you wish + to do session tracking on sub login { $session = time; } sub check_timeout{ my $now = time; $expired = 1 if (($now-$session)>600) # 10 minute timeout } if($expired) { print header(); print h3('Session timeout. No soup for you') } else { # serve the soup ... your code here and then finish it with: $session = time; # that is, reset the timeout with each ne +w activity }
Now in session_track.pm (This code was ripped directly form the Camel Book.)
package session_track; use Carp; use strict; use warnings; use warnings::register; my $count =0; sub TIESCALAR { my $class = shift; my $filename = shift; my $fh; if (open $fh, "<", $filename || open $fh, ">", $filename) { close $fh; $count++; return bless \$filename, $class; } carp "Can't tie $filename: $!" if warnings::enabled(); return; } sub FETCH { my $self = shift; confess "I am not a class method" unless ref $self; return unless open (my $fh, $$self); read($fh, my $value, $fh); return $value } sub STORE { my ($self,$value) = @_; confess "I am not a class method" unless ref $self; open my $fh, ">", $$self or croak "can't clobber $$self: $!"; syswrite($fh, $value) == length $value or croak "can't write to $$self: $!"; close $fh or croak "can't close $$self:$!"; } return "true";
update: perrin's point is well taken. unique session id has some good info on the topic

In reply to Re: Re: timeout by earthboundmisfit
in thread CGI session timeout by supersonic

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.