RE: [PHP] Include vs. Header

From: Date: Sun, 08 Oct 2000 17:54:23 +0000
Subject: RE: [PHP] Include vs. Header
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-19099@lists.php.net to get a copy of this message
I have a sort of related question about include/require. Rather than hard code the standard HTML header I want to outptut it using a function in an include file. e.g. <?php function outputHTMLHeader ( $pTitle="Title Of HTML Page" ) { print("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"> <html> <head> <title>$pTitle</title> </head> <body>" ); } ?> This is fine and works on the GET of my page. After my page is posted I do a header() redirect but I get an error saying "Cannot add header information - headers already sent ..." This implies that because the function is included previously in the script, that it is also executed, but no call to this function is made before the header() redirect. If I move the include after the header() then it works fine. I don't however understand why it should behave differently, as including a file with functions in it surely doesn't execute those functions without an explicit call, does it? PHP Version 4.0.2 Win98(2) -----Original Message----- From: Matt McClanahan [mailto:cardinal@dodds.net] Sent: Saturday, October 07, 2000 1:13 AM To: Eugene Yi (InfoSpace Inc) Cc: 'php-general@lists.php.net' Subject: RE: [PHP] Include vs. Header On Fri, 6 Oct 2000, Eugene Yi (InfoSpace Inc) wrote: > Thank you so much for your reply. Will there be any restrictions to call > cookie function if I use include(), since cookie function requires no header > info passed prior to calling it... Well, as with any other HTTP Header, cookies need to be sent before any content. In some circumstances you can work around this with output buffering. http://www.php.net/manual/ref.outcontrol.php Matt -- 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 (#19099) next »