[PHP] HTTP headers and include()
I've written a separate function library for a cluster of web pages, and I then include(slib.php) in each of the web pages, instead of copying 12k of code to each page individually. Some of the pages require (simple) authentication or redirection headers, which some of the code in the library is supposed to handle. Problem is, when I include the library, even though there's no other output to be processed, it still generates the linefeed that triggers sending all the current headers, so if(!headers_sent) {...} fails. Is it possible to include php code without sending headers? I've tried exit() within the library, but that fails to work. Instead, exit causes generation of HTML code (a content type metatag) that is neither in the main page nor the library. I've also tried a simple return() (per the documentation), but that generates a parse error. I'm using Apache 1.3.12, PHP 4.0.2 and Slackware Linux (Not sure which kernel version). Thanks Cas PS: Please CC replies to [EMAIL PROTECTED], since I'm not officially subscribed to this list. Thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] HTTP headers and include()
Andy [EMAIL PROTECTED] wrote in article 003b01c12b23$d1f245d0$0b01a8c0@ANDreY... See if is there some kind of echo before header()s, or HTML sent to browser. No, I've been extremely careful to avoid that. The following are the two test files I've been using to try to solve this.. (sans the -- File Begin/End --) lib.php: -- File Begin -- ?php function do_nothing() {} ? -- File End -- test.php -- File Begin -- ?php include_once(lib.php); if( headers_sent ) { $senthdrs = Headers Sent; } else { $senthdrs = Headers not sent; } ?html headtitlePHP Lib Test/title/head bodyh1PHP Lib Test/h1hr ?php echo( $senthdrs ); ?/body /html -- File End -- End result: PHP Lib Test Headers sent From what I can tell from the documentation and through experimentation, either there's additional headers being generated when php includes the content (a content-type header maybe?) or more likely, after php is done parsing the file and 'removing' the code, it comes back as a single CRLF, which triggers Apache/PHP to send the headers. Actually, that setup makes sense to me, but I'm trying to find out if there is a way around it. Thanx Cas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]