I have a page with a drop-down menu to select a region, and a check mark to allow the region to be remembered in future sessions.

When the user selects a region and clicks on "GO", the redirection works. If the user checks the "Remember my selection" box, a cookie is set, but redirection fails. The browser merely displays "Location: http://www.somelocation.com".

Also, how can I get it so that, after the cookie is set, it will automatically be retrieved when the main page is called, so that redirection will automatically take place and appear invisible to the user?

Thanks

use CGI qw/:standard/; my $query = new CGI; my $cookie_in = $query->cookie('region'); if ($cookie_in) { if ($cookie_in eq "americas") { print "Location: http://www.google.com\n\n"; } elsif ($cookie_in eq "canada") { print "Location: http://canada.gc.ca\n\n"; } else { print "Location: http://www.belimo.org\n\n"; } } else { my $checked = param(checked); my $region = param(region); if ($checked eq "yes") { my $cookie_out = $query->cookie(-name=>'region',-value=>$reg +ion,-expires=>'Saturday, 31-Dec-04 16:00:00 +GMT',-path=>'/',-domain=>'194.69.170.21'); print $query->header(-cookie=>$cookie_out); } if ($region eq "americas") { print "Location: http://www.google.com\n\n"; } elsif ($region eq "canada") { print "Location: http://canada.gc.ca\n\n"; } else { print "Location: http://www.belimo.org\n\n"; } }

In reply to redirection failing when cookie is set by Anonymous Monk

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.