There's more than one way to this this of course, but here are a few:

1. Within CGI.pm

#!/usr/bin/perl use strict; use warnings; use CGI; my $cgi = CGI->new; my $cookie = $cgi->cookie(-name => 'test', -value => 'testval', -expir +es => "+2h"); print $cgi->redirect( -location => 'http://perlmonks.com', -cookie => $cookie );
2. Generate redirect with CGI, and scrape cookies from the session object's proposed header
#!/usr/bin/perl use strict; use warnings; use CGI; # Define the session object however you were before, # I can't emulate it as you didn't say what # class was being used use Something; my $session = Something->new(); # Get the header that the session object wants to output my $session_header = $session->header(); # Filter out everything other than Set-Cookie headers $session_header = join("\n", grep /^Set-Cookie/, split("\n", $session_ +header)); #output the Set-Cookie headers if ($session_header) { print $session_header . "\n"; } #output the headers that CGI generates my $cgi = CGI->new; print $cgi->redirect('http://perlmonks.com');
#1 would be my preferred solution.
#2 is a bit too hackish for my tastes, and any developer who inherits the project will likely hurt you.

In reply to Re: [CGI] redirect after headers have been printed by imp
in thread [CGI] redirect after headers have been printed by hesh

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.