RE: [PHP] header() ???

From: Date: Thu, 14 Sep 2000 05:09:48 +0000
Subject: RE: [PHP] header() ???
Groups: php.general 
Request: Send a blank email to php-general+get-16709@lists.php.net to get a copy of this message
Sonia. I would forget about using Header(), _unless you specifically need to use it_ 99% of the time you can get away without needing it. PHP sends the header information implicitly immediately before the first textual output, (unlike Perl). In cases where you explicitly need to send the header information, use the Header function. (Generally this is on redirects, creating cookies or sending something other than text - ie if you were producing a gif file.) Example: PHP will send the correct header info immediately before outputting the first character in the header.html file <?php include "header.html"; [...] ?> Example 2 PHP will send the correct header information immediately before outputting the "This is text portion". NOTE: This can cause problems if you have stray lines in your php source before the first <?php and you inadvertantly send a blank cr/lf before you try to do a SetCookie or Header. This is text <?php ?> Example 3 Using Header to send wap as the content type <?php header( "Content-type: text/vnd.wap.wml" ); ?> Have a good look at the manual - http://www.php.net/manual/function.header.php If should clarify things. -----Original Message----- From: Sonia Tsui [mailto:Stsui@villamontage.com] Sent: September 14, 2000 12:50 PM To: 'Jason Murray' Cc: 'php-general@lists.php.net' Subject: RE: [PHP] header() ??? Jason, I see. So even if the content of the other page resides on the same server of the current page, is it still better to use header()? thanks ---Sonia -----Original Message----- From: Jason Murray [mailto:Jason.Murray@melbourneit.com.au] Sent: Wednesday, September 13, 2000 10:50 PM To: 'Sonia Tsui' Cc: 'php-general@lists.php.net' Subject: RE: [PHP] header() ??? > I checked the book "Professional PHP Programming" and > refer to how they use header(): > > if (!authenticateUser($cookie_user, $cookie_passwd)) { > header("Location:http://$HTTP_HOST/$DOCROOT/default.htm"í²+kÌ > ’j%bàØŸC); > exit(); > } > > what difference does that make if I do this instead: > if (...) { > include "http://$HTTP_HOST/$DCROOT/default.htm"); > exit(); > } > > I guess my question is really this: header is used here to > redirect user to other pages, but is it equivalent of doing this > using include in this case? If you include it, you are presenting the contents of the other page as the current page. If you redirect to it, you are sending the browser to a different page. IMHO you should never include() from http:// anyway, since the remote server may be down or timed out. Jason -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#16709) next »