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

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

I want to set a Cookie and then jump to a different location that will use this cookie. Can I do that?

Thanks

Originally posted as a Categorized Question.

  • Comment on Can I set a Cookie and then jump to another location?

Replies are listed 'Best First'.
Re: I wanna set Cookie and then jump to other location.How I do?
by Anonymous Monk on Jun 29, 2000 at 09:56 UTC
    Looks like it works if you call header.
    #!/usr/bin/perl -w use CGI; use CGI::Cookie; my $q = new CGI; my $Cookie = new CGI::Cookie(-name=>'MyCookie', -value=>1); print $q->header(-cookie=>$Cookie, -location=>'http://perlmonks.org');
Re: Can I set a Cookie and then jump to another location?
by sinan (Sexton) on Aug 27, 2000 at 12:19 UTC
    You cannot use the cookie in the first time it is set. (Personal experience)

    You if you reload the new page, you will see that it works.

    The solution is to have the users click on a link on the original page to go to the new page. Or, you can have the Cookie set in the previous page.

    Try to use the javascript re-direct method instead:
    <body onLoad="window.location.href = blah.htm;">
    This will only work if your user has JavaScript enabled.

    Actuallly, WWW Consortium has information on HTTP headers at ftp://ftp.isi.edu/in-notes/rfc2616.txt.

    These might be very useful.
    Sinan
Re: Can I set a Cookie and then jump to another location?
by Anonymous Monk on Sep 14, 2003 at 14:45 UTC

    Re: Can I set a Cookie and then jump to another location?

    Originally posted as a Categorized Answer.