Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: CGI and Redirect/URI/Location

by Hero Zzyzzx (Curate)
on Jun 18, 2001 at 18:13 UTC ( [id://89291]=note: print w/replies, xml ) Need Help??


in reply to CGI and Redirect/URI/Location

The italics below are my emphasis.

From the "Creating the HTTP Header" section of the CGI.pm docs:

Creating the Header for a Redirection Request

   print $query->redirect('http://somewhere.else/in/the/world');

This generates a redirection request for the remote browser. It will immediately go to the indicated URL. You should exit soon after this. Nothing else will be displayed.

You can add your own headers to this as in the header() method.

You should always use absolute or full URLs in redirection requests. Relative URLs will not work correctly.

An alternative syntax for redirect() is:

print $query->redirect(-location=>'http://somewhere.else/', -nph=>1);

So, you'd create your header like this:
print $q->redirect(-location=>"http://$URL",-cookie=>$c);

Replies are listed 'Best First'.
Re: Re: CGI and Redirect/URI/Location
by LeGo (Chaplain) on Jun 19, 2001 at 01:58 UTC
    here is where I am now...
    This works in Netscape but not IE?
    $c = new CGI::Cookie(-name => 'login', -value => $login2, -expires => '+3M', ); $d = new CGI; print $d->redirect(-cookie=>$c, -location=>"$URL");
    This works in IE but not Netscape?
    $c = new CGI::Cookie(-name => 'login', -value => $login2, -expires => '+3M', -domain => '.mydomain.com' ); $d = new CGI; print $d->redirect(-cookie=>$c, -location=>"$URL");
    I didn't think that the domain should make a difference for IE but it did. So I tried adding -nph=>1 to both $c and $d seperately. When I added it to $c it did not do anything. When I added it to $d it gave an Internal Service Error.

    Are there any comments or suggestions that I might be missing on my code here? I would like for it to work in both IE and Netscape obviously.

    Also anyone know why netscape takes about 5 seconds to process and IE doesn't take any time?

    LeGo

      I'm confused. You seem to be mixing function and OO calls to CGI. I'm not sure if this is causing your problem, but it might. I've never experienced issues with cookies working with one browser and not the other.

      Some things to try:

      1. Use all OO calls to CGI, thusly:
        my $q = new CGI; my $c = $q->Cookie(-name => 'login', -value => $login2, -expires => '+3M', -domain => '.mydomain.com' ); print $q->redirect(-cookie=>$c, -location=>$URL);
      2. I doubt this will mean anything, but I don't think you need the double quotes around $URL.
      3. You can only set a cookie for the domain that the script was requested from. . .as a security measure. If your domain is "foo.com" you can only set a valid cookie for this domain. I think you're aware of that, given the way you set your domain in your cookie. So if your redirect is to a different domain, you can't set a cookie for that domain, only the old one.

      Good Luck!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2025-04-30 00:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.