note 63293 added to function.ob-start

From: Date: Sat, 18 Mar 2006 17:56:25 +0000
Subject: note 63293 added to function.ob-start
Groups: php.notes 
Request: Send a blank email to php-notes+get-106041@lists.php.net to get a copy of this message
i am trying to use object oriented code which has an HTMLBegin method and an HTMLEnd method, and include this object into some pages on my site, and i wrap these functions outputs around content on each page. this method takes in a few variables such as the page title, and it constructs all the top HTML code to the opening of the body tag, to save me some code, and the end method takes over and closes all HTML elements including the body. my problem is, i use ob_start at the top of the HTMLBegin before any output is sent, and i flush the buffer at the end of the HTMLEnd function, yet its not working! heres a sample of the html in the first method: <?php function HTMLBegin(variables){ ob_start(""); (bunch of other code) //close the php so i can output some html here ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title><?php echo $title;?></title> ... //reopen php tags and close the function, carry out rest of code, etc <?php } ?> at the line where i attempt to output the title, output buffering is not apparently working! if i make a page like this: <?php (include and instantiate the object) $instance->HTMLBegin(variables); page content <?php header("Location: http://www.example.com/"); ?> $instance->HTMLEnd(); i get errors and it doesnt send the headers! PHP Warning: Cannot modify header information - headers already sent by (output started at... PHP Notice: ob_end_flush(): failed to delete and flush buffer. No buffer to delete or flush. in... the headers are "already sent" at the line where i output $title, and the second error occurs when i try to flush the output buffer at the bottom. it is almost as if output buffering is not taking place at all, yet, the error takes place after i outout the value only! this same exact code used to work PERFECTLY before i upgraded to php 5.1.2 or whatever newest version is, i was using php 5.0.4 before i upgraded. can ANYONE tell me exactly what is going wrong, and how i might fix this problem? it seems to be very hard to find out exactly what changes occur between php versions, and the manual doesnt seem to document why this happens anywhere. ---- Server IP: 66.207.199.35 Probable Submitter: 198.53.253.173 ---- X-Spam-Status: No, hits=4.4 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, HTML_MESSAGE,HTML_TAG_BALANCE_HTML,HTML_TITLE_EMPTY autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.ob-start.php Edit -- http://master.php.net/note/edit/63293 Del: integrated -- http://master.php.net/note/delete/63293/integrated Del: useless -- http://master.php.net/note/delete/63293/useless Del: bad code -- http://master.php.net/note/delete/63293/bad+code Del: spam -- http://master.php.net/note/delete/63293/spam Del: non-english -- http://master.php.net/note/delete/63293/non-english Del: in docs -- http://master.php.net/note/delete/63293/in+docs Del: other reasons-- http://master.php.net/note/delete/63293 Reject -- http://master.php.net/note/reject/63293 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#106041) next »