Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CGI::Session param expiration

Status
Not open for further replies.

Zhris

Programmer
Aug 5, 2008
254
GB
Hello,

From what I was told, if you do not explicitly set an expiration for a session or a param, then it will only expire once the browser has been closed entirely. I have even tested this with a simple script, and seems to be the case.

However, I have recently edited a script, and at no point do I set an expiration time, but it seems to automatically expire after approximately 10 seconds of inactivity. In order to stop this from happening I have had to use the following line of code (which cancels any expiration):

Code:
$session->expire('Attribute', 0);

I am unsure whether this is neccessary, or there is something I am doing wrong in my script (although as I mentioned at no point do I set an expiration time).

I am quite new to using sessions therefore i'm unexperienced. Here is the session section of my script (note that TimeoutBaskets subroutine contains no session code (it simply deletes files in a directory that were last modified more than $timeout seconds ago)):

Code:
my $time = time;
#
my $info = TimeoutBaskets ($basketwfpdir, $baskettodir, $productspath, $temppath, $time, $timeout);
#
my $session = new CGI::Session();
print $session->header();
#
my $sessionid = $session->id();
my $random = int(rand(89999)) + 10000;
my $generatedbasketid = $sessionid.'-'.$time.'-'.$random;
#
unless ($session->param(-name=>'BasketId')) {
	$session->param(-name => 'BasketId', -value => $generatedbasketid);
}
my $basketid = $session->param(-name=>'BasketId');
#
my $basketwfppath = $basketwfpdir.'/'.$basketid.'.txt';
if (!-e "$basketwfppath") {
	$session->param(-name => 'BasketId', -value => $generatedbasketid);
	$basketid = $session->param(-name=>'BasketId');
	$basketwfppath = $basketwfpdir.'/'.$basketid.'.txt';
	open (FILE, ">$basketwfppath") || die qq(Cannot Open File);
	flock (FILE, 2) || die qq(Cannot Flock File);
	close (FILE) || die qq(Cannot Close File);
}
#
if ($params{'ViewProducts'}) {
	if ($params{'ViewProducts'} ne 'Continue Shopping...') {
		$session->param(-name => 'CarryCategory', -value => $params{'ViewProducts'});
		$params{'Category'} = $params{'ViewProducts'};
	}
	else {
		$params{'Category'} = $session->param(-name=>'CarryCategory');
	}
}
#
$session->expire('BasketId', 0);
$session->expire('CarryCategory', 0);
#
$session->flush();

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top