use CGI; use CGI::Session; use strict; my $q = new CGI; print $q->header( "text/html" ); #--------------------------------------# #------------- Variables --------------# #--------------------------------------# my %valueHash; my %newHash; GrabParams(); my $session; my $SID; #--------------------------------------# #---- New/Open Session Condition ------# #--------------------------------------# if ($valueHash{"sessPass"} == 1) { $session = new CGI::Session(undef, undef, {Directory=>'tmp/sessions'}) or die CGI::Session->errstr; #--> creates a CGI::Session Object for use $SID = $session->id; }else{ $session = new CGI::Session(undef, $valueHash{"session"}, {Directory=>'tmp/sessions'}) or die CGI::Session->errstr; #--> Open session my %newHash = %{$session->param('valueHash')}; #--> load session hash and save it into a new hash (had to derefference it first with %{}) #--> Loop through the load hash and push the values into valueHash #--> so the new and old parameters are in one hash #-------------------------------------------------------------------> while (my($k, $v) = each(%newHash)) { $valueHash{$k} = $v; printf("
key: %s value: %s", $k, $v); } #--> After loading session variables and setting them to the new variables in valueHash #--> we need to clear the session hash values so we can rewrite the new values #---------------------------------------------------------------------------------------> $session->clear(); } $session->param('valueHash', \%valueHash); $session->flush(); #--------------------------------------# #------------ Functions ---------------# #--------------------------------------# sub GrabParams{ my ( $paramName, $paramValue); foreach $paramName ($q->param) { foreach $paramValue ($q->param( $paramName )) { $valueHash{ $paramName } = pack 'U0A*', $paramValue; } } }