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:
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 subroutine was get_timestamp() - here it is:
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); }
The culprit line is:  my $time_frame = chop($meta_configs{login_cookie_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.


In reply to chop and CGI.pm cookie problem? by michellem

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.