in reply to redirect and cookie problems

Cookies *must* be sent in the header; reprinting CGI->header() with the cookie will do nothing. So you need to delay printing "cgi->header()" until you have your cookie information.

If you want to redirect, on the other hand, you do not want to print header(), but use the CGI redirect() function.

With the code you have above, you must rethink your logic on how you authenicate and send the user on. You won't easily modify this code to do that.

(I'm guessing that merlyn has a column on what you want to do... :-)


Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

Replies are listed 'Best First'.
Re: Re: redirect and cookie problems
by Anonymous Monk on Jun 14, 2001 at 06:04 UTC
    thank you, but were in the code should i put this "CGI->header()"? i do not see that in my program at all you make it sound like I do. also do I have to add anything to the () portion of it to make the cookie work. Also wht goes inside the () portion of redirect? is it just the address of the page you want to direct them to.
      Well, you need to use "$cgi->header(-cookie=>cookie_stuff)" as the first thing that you print out to get the cookies to be set.

      Redirect just needs the URL as the call.

      Look at the docs for CGI.pm for more details.


      Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
      For redirection, you may want to read up on this: Generating a Redirection Header.

      Update: I think I was wrong there, I apologize.

      The redirect() function redirects the browser to a different URL. If you use redirection like this, you should not print out a header as well. As of version 2.0, we produce both the unofficial Location: header and the official URI: header. This should satisfy most servers and browsers - from CGI documentation

      Update 2: Depending on what you want to do - I most likely misunderstood. If you want to completely redirect the user - then these nodes will help. CGI and redirect and Trying to redirect ... - I apologize for not pointing to this earlier.. my brain isn't/wasn't working. You want to use Location - to redirect the user to a new site. But, if you just want to inform the user of the new location - then use URI: header - I believe you used that correctly:
      print URI: http://www.storm.prohosting.com/cgi-bin/warropr.pl;

        I do not under stand what should i change the redirect line to? or are you saying not to do a header() if so then I can not use cookies can I?
        Might just be me being pedantic (as ever), but according to my copy of RFC2068 (HTTP/1.1); the "correct" method to do redirects is to return HTTP status 301, and to give the new URI in a Location header. The RFC goes on to indicate that you should also include a "short hypertext note" with a hyperlink to the new URI

        --
        RatArsed