michellem has asked for the wisdom of the Perl Monks concerning the following question:
This is a really wierd one. I have come across an issue where issuing a chop command in a subrotine called before I set a cookie using CGI.pm prevents that cookie from being set.
Yeah, I know. It sounds totally strange. But it's the only explanation I can find, and replacing my chop with a simple substr eliminates the problem!
There are no errors with that statement in the error logs, and execution of the script continues unabated, so I know that's not the problem. Has anyone else run into this? What could this be due to?
Here's a bit of code:The culprit subroutine was get_timestamp() - here it is:if (($user)&&($passcheck)) { # create a MD5 hash for session management my $session_brand = md5_hex(rand()); (my $session_timestamp, my $session_expiration) = get_timestam +p(); my $session_done = set_session($session_brand,$session_timesta +mp, $session_expiration); my $cookie = cookie(-domain=>"$meta_configs{xina_domain}", -name=>"$meta_configs{login_cookie_name}", -value=>"$session_brand", -path=>"$meta_configs{login_cookie_path}", -expires=>"$meta_configs{login_cookie_expi +ration}"); print $q->header(-cookie=>[$cookie]); # cookie set
The culprit line is: my $time_frame = chop($meta_configs{login_cookie_expiration});sub get_timestamp { (my $year, my $month, my $day, my $hour, my $min, my $sec) = Today +_and_Now(); my $now_ts = "$year-$month-$day $hour:$min:$sec"; my$Dd; my $Dh; my $Dm; # cookie expiration is always in the form 10m or 1d my $time_frame = chop($meta_configs{login_cookie_expiration}); if (($meta_configs{login_cookie_expiration} =~ /[0-9]+/)&&($time_f +rame eq "m")) {$Dm = $meta_configs{login_cookie_expiration};} elsif (($meta_configs{login_cookie_expiration} =~ /[0-9]+/)&&($tim +e_frame eq "h")) {$Dh = $meta_configs{login_cookie_expiration};} elsif (($meta_configs{login_cookie_expiration} =~ /[0-9]+/)&&($tim +e_frame eq "d")) {$Dd = $meta_configs{login_cookie_expiration};} else {$Dh = 1;} # make a default expiration of 1 hour (my $nyr, my $nmo, my $nday, my $nhr, my $nmin, my $nsec) = Add_De +lta_DHMS($year, $month, $day, $hour, $min, $sec,$Dd, $Dh, $Dm, 0); my $expiration = "$nyr-$nmo-$nday $nhr:$nmin:$nsec"; return ($now_ts, $expiration); }
If I replace that with: my $time_frame = substr ($meta_configs{login_cookie_expiration},-1,1); Everything works fine!
Thanks for any ideas. I'm not stuck, I obvioulsy solved the problem, but it seems strange, and I'd love to find out what the issue really is.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: chop and CGI.pm cookie problem?
by antirice (Priest) on Jul 31, 2003 at 18:51 UTC | |
by michellem (Friar) on Jul 31, 2003 at 19:30 UTC | |
by antirice (Priest) on Jul 31, 2003 at 20:09 UTC | |
by michellem (Friar) on Jul 31, 2003 at 20:16 UTC | |
Re: chop and CGI.pm cookie problem?
by RMGir (Prior) on Jul 31, 2003 at 19:13 UTC | |
Re: chop and CGI.pm cookie problem?
by skyknight (Hermit) on Jul 31, 2003 at 18:51 UTC | |
by michellem (Friar) on Jul 31, 2003 at 19:26 UTC |