Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

how do I set a cookie and redirect

by psmail (Initiate)
on Jun 29, 2001 at 19:22 UTC ( [id://92671]=perlquestion: print w/replies, xml ) Need Help??

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~;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://92671]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-18 23:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found