in reply to Re^2: Perl CGI Cookies "Content-Type:text/html" showing at top of html.
in thread Perl CGI Cookies "Content-Type:text/html" showing at top of html.

one print header(-cookie=>$cookie);

two print "Content-type:text/html\n\n";

Also, use CGI, don't mess with QUERY_STRING on your own

Replies are listed 'Best First'.
Re^4: Perl CGI Cookies "Content-Type:text/html" showing at top of html.
by lauratheperlnewbie (Initiate) on Aug 19, 2011 at 09:49 UTC
    Ahh yep I see why it is happening, However to set my cookie correctly I must print the cookie into the header(or so ive read); print header(-cookie=>$cookie); and for the html to work correctly I need to print  print "Content-type:text/html\n\n"; so how do I fix this?

      I must print the cookie into the h....and for the html to work correctly I need

      Kindly go back to the manuals I linked :)

      You can only print the header once, and once only, this is the rule of HTTP, no way around it

      Instead of broken logic

      if ( blah ){ print header( and cookie ); } print header;
      use correct logic for print headers only once
      if ( blah ){ store cookie in variable } print header ( and $cookie )