Syntax with Set-Cookie

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

This script worked through earlier versions of both IE and FF, but the
newer versions aren't writing the cookie if $remember=1. If
$remember=0 then the cookie is set correctly, so I'm pretty sure that
the error is with the $expires variable. I'm guessing that there's a
typo that the older versions didn't recognize.

Are there supposed to be hyphens in the $expires date? If so, then do
you see any other reason that $expires would be causing a problem?

In this script, $remember is determined by a standard checkbox.



# Log In Script
my $expires;

if ($remember) { $expires = "Sun, 04-Jan-2015 00:00:00 GMT"; }
($found, $banned) = log_in($username, $password, $expires);

sub log_in {

  # snip irrelevant authorization info

  print "Set-Cookie: user=$userID; path=/; expires=$_[2]\n";
  return $found, $banned;

Re: Syntax with Set-Cookie

Quoted text here. Click to load it

My guess is @_ is being overwrittin by the time you use it.
It is always a good idea to save away your sub's startup parameters right away.

  sub someSub {
    my $expires = $_[2] || 'DEFAULT VALUE OR ACTION';

In this case, since $expires is accessible by sub log_in(), you might
try changing the print line to something like:

  if (! $expires) {
    #remember was not checked, use default 'expires' value
    $expires = 'DEFAULT';
  print "Set-Cookie: user=$userID; path=/; expires=$expires\n";


Site Timeline