Re: Re: http header

From: Date: Thu, 29 Apr 2004 08:21:52 +0000
Subject: Re: Re: http header
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-184929@lists.php.net to get a copy of this message
Torsten Roehr a écrit :
header("Location: http://www.yahoo.com"); exit; Without "exit;" the header redirect soemtimes didn't work for me.
It the way http redirects (302) works. See HTTP/1.1 spec (rfc2616). See below for some details [ Perhaps the 'redirect' questions should appear in the FAQ, since I feel many dont understand what happens behind the scene. The 'Livehttpheaders' extension for mozilla/firefox can help ] 1. header('Location: absoluteURL') defines and send a http header like ------------------------------------------- HTTP/1.1 302 Found Date: ... Server: Apache/x.y.z ... Location: absoluteURL ... Content-Type: text/html ------------------------------------------- 2. everything echo|print ed after header() is sent as the http body. (with 'exit;', body is empty) So the client get a 302 http header with content. It can display content (which should contain a href with the redirected absoluteURL) or make a new http request to the absoluteURL. Depends on client -- really old ones just display content, so using just 'exit;' is of no help for them. PS The Location header must use ABSOLUTE urls (RFC2616). So using relative urls may result in surprising or undefined results, even if new browsers try to rebuild the absolute url from the relative one. Christophe

« previous php.general (#184929) next »