Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi People .... just needed some help on a cookie issue.

I have code which looks like -

my $yySetCookies1 = cookie(-name => "test", -value => "test", -path => "/", -expires => ""); print header(-status=>"200 OK", -cookie=> $yySetCookies1);


to set a cookie. Now the thing is that on my localhost server it runs fine. But on my remote web hosting (some hosting company), it prints out

Status: 200 OK Set-Cookie: test=test; path=/ Date: Thu, 27 Feb 2003 05 +:41:26 GMT Content-Type: text/html; charset=ISO-8859-1


onto the web page. Now I've removed any other header info form my remote host script (even using CGI->header, gives me a similar problem).

What would you guys advise?

Please do let me know.

Thanks, SP

Replies are listed 'Best First'.
Re: Cookie question ....
by bart (Canon) on Feb 27, 2003 at 12:05 UTC
    You may have found a workaround, but I'm still curious to why it doesn't work... For some reason, CGI.pm isn't outputting proper linebreaks (preferably CR+LF) as it should... If it's a bug, I'd like the maintainer of that module to be warned.

    Judging from the module's code, that is defined by the global variable $CGI::CRLF. Can you check what it contains — on the server, of course?

    use CGI; print "Content-type: text/plain\n\n"; print join " ", unpack 'C*', $CGI::CRLF;
    Except on EBCDIC systems, it ought to look like
    13 10
      I seriously doubt if the linebreaks are the problem. Most likely the browser is interpreting the late header information as html and just ignoring the line breaks. If he viewed the source of the page the line breaks would be there.

      -caedes

Re: Cookie question ....
by caedes (Pilgrim) on Feb 27, 2003 at 05:59 UTC
    It looks like the HTTP header is getting printed out and parsed by the server before you print the header for the cookie (the code you posted). Please post the rest of the code and we might be able to show you where.

    Also, are you using CGI or mod_perl?

    -caedes

      Caedes,

      Thanks for your response.

      This is all the code in the beginning of my script-
      #!/usr/bin/perl my $yySetCookies1 = cookie(-name => "test", -value => "test", -path => "/", -expires => ""); print header(-status=>"200 OK", -cookie=> $yySetCookies1); use CGI qw(:standard); # Must be used to get the param() func +tion #use CGI; use CGI::Carp (fatalsToBrowser); #use CGI::Cookie; use strict; use OLE; use Net::SMTP; # Yes, this will work on windows. use MIME::Base64;


      I'm using CGI.

      ANy ideas?

      Thanks, SP
        Nothing there seems to be the cause of your problem although you would do well to clean up your code just a bit. You have a bareword "fatalsToBrowser" on the 6th line. I suggest something like:

        #!/usr/bin/perl -w use strict; use CGI::Carp qw(fatalsToBrowser); use CGI qw(:standard); my $yySetCookies1 = cookie( -name => "test", -value => "test", -path => "/", -expires => "" ); print header( -status=>"200 OK", -cookie=> $yySetCookies1 );

        -caedes