http://www.perlmonks.org?node_id=92671

psmail has asked for the wisdom of the Perl Monks concerning the following question: (cgi programming)

I am using CGI_Lite and I want to set a cookie and redirect to a url. I don't want to use CGI.pm which has a redirect method. Is there a way to redirect with setting a cookie and without using CGI.pm? Thanks

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: how do I set a cookie and redirect
by kwaping (Priest) on Jul 24, 2006 at 18:34 UTC
    Here's an example of how to do it using CGI's OO interface.
    use CGI (); my $cgi = CGI->new(); my $cookie = $cgi->cookie(-name => 'test', -value => '1'); print $cgi->redirect(-uri => 'http://www.perlmonks.org/', -cookie => $ +cookie);
Re: how do I set a cookie and redirect
by epoptai (Curate) on Jun 30, 2001 at 03:39 UTC
    Just print the headers like so:
    print "Set-Cookie: name=value; path=path; domain=domain; expires=expir +es;\n"; print "Location: http://whatever.net\n\n";
Re: how do I set a cookie and redirect
by SmokeyB (Scribe) on Sep 27, 2002 at 20:23 UTC
    After you set your cookie, print out the following meta tag in the header of the file. It'll use the browser's refresh to direct you to a new page.
    print qq~<meta http-equiv="refresh" content="0;URL=url.html">\n~;