I've now learned far more about cookies than I ever wanted to know, but I still haven't been able to solve my problem after several days of exhaustive research and effort.

My application is attempting to store the name of an individual when they complete an application, but it appears that the :
print "Content-type: text/html\n\n";
is causing my problem. The cookie data appears on the screen above the confirmation message after the application is submitted.

I've read that the cookie must be written before the "content" line is encountered, but how does one do that if they must first display a screen to collect the data? Is there a way to negate the effect of the "content" line until data must again be displayed?

I've moved the "Set-cookie:" command to a separate script, accessed as a subroutine after a "require" command is issued, but the "content" status persists.

I hope that I've made the problem clear. During the past few days I've tried everything I can think of to resolve this problem, and failed. Hopefully, it's something simple that I've overlooked.

Here's the code that calls the subroutine :
require "common.cgi"; write_cookie;
And here's the "common.cgi" script:
#!/usr/bin/perl # sub write_cookie { $wc_namef = $INPT{'reg_custnamef'}; $wc_namemi = $INPT{'reg_custnamemi'}; $wc_namel = $INPT{'reg_custnamel'}; print "Set-Cookie: b_first=$wc_namef; path=/; expires=Wed, 30-Dec- +2020 00:00:00 GMT;"; print "Set-Cookie: b_mid=$wc_namemi; path=/; expires=Wed, 30-Dec-2 +020 00:00:00 GMT;"; print "Set-Cookie: b_last=$wc_namel; path=/; expires=Wed, 30-Dec-2 +020 00:00:00 GMT;"; } 1;
Perhaps most frustrating of all is the knowledge that at some point during trial and error testing, I affected the existing cookie record for the site, but I must have been asleep at the switch because I don't know which of the hundreds of attempts worked, nor have I been able to duplicate it. :-)

In reply to Cookies write to screen, not to cookie file by TJD

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.