Thankyou all,

There's a lot of info here but I guess that I can summaries it as follows:

1) Do not redirect if the page is visited as the result of a POST
2) Keep text after header("Location: ...) to an absolute minimum. Namely <a
href="...">...</a>
3) Use absolute URLs not relative ones.
4) If you abide by 1,2&3 it should work with all (most) browsers

Thanks for all the help

Henry.


"Christophe Chisogne" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Vincent Jansen wrote:
> >>If you output a location header then I don't know what the browser will
> >>do with text sent after that.  Hopefully nothing!
>
> Be carefull to exit() php code after header-location
> (and some text, see below): otherwise code following
> will be executed! It's a common error.
>
>  > I experienced some strange behaviour(=no redirect at all!!) with a
>  > script that send data after the location header.
>
>  > header("Location: http://somesite.nl";);
>  > die();
>
> To make things work, just follow the HTTP/1.1 spec[1]:
> PHP just sends a "302 Found" code in the http header when using
> PHP header("Location: ..."). It's a 'temporary' redirect (browser
> should continue to use previous url), as opposed to a 'permanent'
> redirect (http code 301). Text sent after that fills the body
> of the http request (ex GET), and it shoud
> "contain a short hypertext note with a hyperlink to the new URI(s)."
> (unless request is HEAD) [2]. Also note that the location url
> must be absolute, not relative [3].
>
> So use
>
> 1. header("Location: $url"); // $url must be absolute
> 2. echo "...<a href='$url'>...</a>..."; // send body of request
> 3. exit() or die(); // to avoid executing of code following
>
> Forgetting 1 is common error: not all browser will 'redirect' then,
> but most modern browsers do, helping uncompliant applications.
>
> Forgetting 2 makes impossible to see the redirected page with old
> browsers (they only display the body of 30x request, allowing
> user to manually follow it.. I vaguely remember netscape 2 or 3).
>
> Forgetting 3 causes bugs, sometimes hard to find.
>
> Note that things can be different with POST requests.
> "If the 302 status code is received in response to a request other than
> GET or HEAD, the user agent MUST NOT automatically redirect the request
> unless it can be confirmed by the user, since this might change the
> conditions under which the request was issued." [4]
>
> The curious about redirects will read 302 and 301 codes,
> but also 303 and 307 (only since http/1.1)
>
> [1] http/1.1 RFC (w3c html version)
> http://www.w3.org/Protocols/rfc2616/rfc2616.html
> [2] 302 http code
> http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.3
> [3] Location http header
> http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30
>
> Christophe

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to