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

I have a CGI program that uses cookies to maintain store session information. In order to send the cookie, I have to send it as part of the header information. The cgi program then takes and processes form variables. After that, I want to have the cgi program redirect to another URL. Is there a way to do this after a header has been specified.?
print "Location: http://nameofurl\n\n";
<-Does not work since the header was already specified. The header looks like this -
$cookie = $cgimain->cookie(-name => CGISESSID, -value => $session->id, -path => '/', -expires => '+2h', ); print $cgimain->header(-cookie => [$cookie] );

Replies are listed 'Best First'.
Re: How do I redirect to another URL after I already specified an html header?
by borisz (Canon) on Jun 08, 2004 at 00:16 UTC
    _Instead_ of printing your headers out, do all at once. Since I do not use the CGI module, it may work a little different, but this is the way to go.
    print $cgimain->redirect( -Location => 'http://nameofurl' -nph => 1, -status => 302, -cookies => $cookie );
    Boris
Re: How do I redirect to another URL after I already specified an html header?
by eXile (Priest) on Jun 08, 2004 at 00:53 UTC
    Assuming you can't get your $cgimain-object to print additional headers, you could use an http-equiv meta-thingie in your html code:
    <html> <head> <meta http-equiv="Refresh" CONTENT="0; URL="http://www.emileaben.com/"> </head> <body></body> </html>