in reply to Re: redirection failing when cookie is set
in thread redirection failing when cookie is set

Well, now redirection works when you check the "Remember my selection box", but the cookie is never set....I'm not sure why. Before, the cookie was being set, but redirection would not work in this case.

Here is the modified code:

use CGI qw/:standard/; my $query = new CGI; my $cookie_in = $query->cookie('region'); if ($cookie_in) { if ($cookie_in eq "americas") { print $query->redirect('http://www.google.com'); } elsif ($cookie_in eq "canada") { print $query->redirect('http://canada.gc.ca'); } else { print $query->redirect('http://www.un.org'); } } else { my $checked = param(checked); my $region = param(region); if ($region eq "americas") { $redirect_uri = "http://www.google.com"; } elsif ($region eq "canada") { $redirect_uri = "http://canada.gc.ca"; } else { $redirect_uri = "http://www.un.org"; } 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->redirect(-cookie => $cookie_out, -uri => $redi +rect_uri); } else { print $query->redirect($redirect_uri); } }

Replies are listed 'Best First'.
Re^3: redirection failing when cookie is set
by kutsu (Priest) on Sep 09, 2004 at 15:02 UTC

    You will proably need to set the domain, see my eariler code, to get the cookie to work, see sandfly's explaination on why.

    "Cogito cogito ergo cogito sum - I think that I think, therefore I think that I am." Ambrose Bierce

      I changed the domain from '194.69.170.21' to "$ENV{HTTP_HOST}", and the results are the same :(
      I changed the domain from '194.69.170.21' to "$ENV{HTTP_HOST}", and the results are the same :(

      Any other ideas? Thanks