Loading ...
Sorry, an error occurred while loading the content.

Setting a cookie from an email message

Expand Messages
  • Octavian Rasnita
    Hi all, I ve tried to set and get a cookie from an HTML mail message. I ve succeeded doing this but only using the server from my localhost. The same script
    Message 1 of 1 , Jan 28, 2003
    • 0 Attachment
      Hi all,

      I've tried to set and get a cookie from an HTML mail message.
      I've succeeded doing this but only using the server from my localhost.

      The same script can set and get cookies if it runs on a remote server, but
      only if I link to it in a web page and not in an email.

      I've tried calling this script using the following url:
      <img src="http://localhost/cgi-bin/script.pl/image.jpg">

      I am wondering why from localhost it can set and get the cookie if called
      from an email message, but if I put the script on another site, it works
      only from a web page.

      Please tell me if you see something that could be wrong with my script, or
      with my Outlook Express settings.

      Thank you.
      Here is the script:

      #!/perl/bin/perl -w

      my $docroot = $ENV{'DOCUMENT_ROOT'};
      my $hostroot = $ENV{'HTTP_HOST'};

      my $out = "$docroot/../writable/image_result.txt";

      use CGI;
      my $q = new CGI;
      my $cook = $q->cookie(-name=>'teddy');

      open (OUT, ">>$out") or die "Can't create $out - $!";
      print OUT "$cook\n";
      foreach my $e(sort keys %ENV) {
      print OUT "$e=$ENV{$e}\n";
      }
      print OUT "\n";
      close OUT;

      #If there is an old cookie, get it, or set a new random one:
      my $cookie = ($cook or int(rand(9999)));

      my $cookset = $q->cookie(-name=>'teddy',
      -value=>$cookie,
      -expires=>'+30d',
      -domain=>$hostroot,
      -path=>'/cgi-bin/');
      print $q->header(-type=>'image/jpg',
      -cookie=>$cookset,
      -expires=>'+30d',
      -Content_length=>'3',
      -Pragma=>'no-cache',
      -Cache_control=>'no-cache');

      print "123";

      Thank you

      Teddy,
      Teddy's Center: http://teddy.fcc.ro/
      Email: orasnita@...
    Your message has been successfully submitted and would be delivered to recipients shortly.