verN Posted April 14, 2007 Share Posted April 14, 2007 hi i am getting the following error and do not know what it means. Warning: Cannot modify header information - headers already sent by (output started at d:\Project\htdocs\seminarmanager\includes\back_header.php:99) in d:\Project\htdocs\seminarmanager\cms_seminars\kegmember\create_kegmember.php on line 128 line 128: [code=php:0]$created = "../kegmember/KEGmember_Created.php?id=".$user; header("Location: $created"); i am using an include function at the top and bottom of the page. like this include ('../../includes/back_header.php'); include ('../../includes/back_footer.php'); when i comment out the following line it works //include ('../../includes/back_header.php'); otherwise i get the error at the top. header is used when someone fills in the form successfully and get directed to another page. The form worked successfully but when i added the includes it doeson't. anyone help this is buuging me Quote Link to comment https://forums.phpfreaks.com/topic/47000-solved-header-problem/ Share on other sites More sharing options...
Glyde Posted April 14, 2007 Share Posted April 14, 2007 You can not have a single print_r, print, echo, or any other flush commands which will send output to the browser. This includes even a whitespace before the opening <?php tag. There must be NO output sent to the browser if you are trying to set a header, or use the setcookie() function. And please, my god, read the large, all capital stickies on the top of the page before you post. http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Just as an explanation which can be added to the stickied post: HTTP response are fairly simple. Here is an example HTTP transaction: 1) Client connects to server, port 80 2) Client sends request: GET /index.php HTTP/1.1 Host: server.com 3) Server sends response: HTTP/1.1 200 OK Content-type: text/html Content-length: 140 Server: Apache 140 bytes of data would be here If PHP echoes data out to the browser, it begins writing where you see "140 bytes of data would be here" above. If you echo data, and you have already begin writing to the body, how can you expect PHP to modify those headers. They have already been sent to the browser now, so the browser already knows the Content-type, Content-length, and Server. There is no longer anything PHP or Apache can do about it. Quote Link to comment https://forums.phpfreaks.com/topic/47000-solved-header-problem/#findComment-229208 Share on other sites More sharing options...
wildteen88 Posted April 14, 2007 Share Posted April 14, 2007 hi i am getting the following error and do not know what it means. Warning: Cannot modify header information - headers already sent by (output started at d:\Project\htdocs\seminarmanager\includes\back_header.php:99) in d:\Project\htdocs\seminarmanager\cms_seminars\kegmember\create_kegmember.php on line 128 line 128: [code=php:0]$created = "../kegmember/KEGmember_Created.php?id=".$user; header("Location: $created"); i am using an include function at the top and bottom of the page. like this include ('../../includes/back_header.php'); include ('../../includes/back_footer.php'); when i comment out the following line it works //include ('../../includes/back_header.php'); otherwise i get the error at the top. header is used when someone fills in the form successfully and get directed to another page. The form worked successfully but when i added the includes it doeson't. anyone help this is buuging me Use output buffering in your case. Add ob_start(); after the opening php tag (<?php) in create_kegmember.php and ob_end_flush() before the closing php tag at the end of the script. Quote Link to comment https://forums.phpfreaks.com/topic/47000-solved-header-problem/#findComment-229213 Share on other sites More sharing options...
verN Posted April 14, 2007 Author Share Posted April 14, 2007 i am new to php and i have been learning it for the past month and a half. This may sound dumb but i don't understand how toc reslove this problem. Quote Link to comment https://forums.phpfreaks.com/topic/47000-solved-header-problem/#findComment-229216 Share on other sites More sharing options...
Glyde Posted April 14, 2007 Share Posted April 14, 2007 As just said by wildteen, you'll need to make use of output buffering. Find the first opening tag in your script. The first opening tag on the first page that is ever executed in your script. To me it looks like that would be back_header.php. Find the first opening PHP tag there, and add ob_start() just after it, as line 2 (line 1 being the opening PHP tag). Now, find the last closing PHP tag in your script, this should probably be in back_footer.php. Just before the closing tag, add ob_end_flush(). Quote Link to comment https://forums.phpfreaks.com/topic/47000-solved-header-problem/#findComment-229219 Share on other sites More sharing options...
verN Posted April 14, 2007 Author Share Posted April 14, 2007 thankyou for very quick replies. I have learnt something new this works now. When looking at the error message it sounded complicated and I can see see the problem in php trying to figure what to call and so on. Can i ask a question what do ob_end_flush() and ob_start(); do? why doesn't ob_end_flush() end with ; thanks again Quote Link to comment https://forums.phpfreaks.com/topic/47000-solved-header-problem/#findComment-229221 Share on other sites More sharing options...
Glyde Posted April 14, 2007 Share Posted April 14, 2007 ob stands for output buffering. Basically, whenever you make an "echo" or a "print" statement, or PHP encounters anything that would normally be sent to the browser as part of the body, it adds it to a buffer. That way, instead of sending the body to the browser, it holds it until you call ob_end_flush(). This allows PHP to modify the headers anywhere before ob_end_flush() because up until that point, no body has been sent out. Quote Link to comment https://forums.phpfreaks.com/topic/47000-solved-header-problem/#findComment-229224 Share on other sites More sharing options...
verN Posted April 14, 2007 Author Share Posted April 14, 2007 thanks for your help i get it now. i understand it alot better now. Quote Link to comment https://forums.phpfreaks.com/topic/47000-solved-header-problem/#findComment-229227 Share on other sites More sharing options...
wildteen88 Posted April 14, 2007 Share Posted April 14, 2007 thanks for your help i get it now. i understand it alot better now. I do not normally suggest using output buffering, as most header errors can sorted out easily. However in your case I think output buffering would better due to your set up. Header errors are really easy to understand. Its just knowing what PHP is reporting to you. Header errors contain two vital bits of information. The first clue is where the output started/ended (highlighted in red below) and the second clue is where the error has occurred (highlighted in blue below): Warning: Cannot modify header information - headers already sent by (output started at d:\Project\htdocs\seminarmanager\includes\back_header.php:99) in d:\Project\htdocs\seminarmanager\cms_seminars\kegmember\create_kegmember.php on line 128 Most people don't understand or miss out the first clue (red) and go for the second clue (blue). That first clue is very important. Quote Link to comment https://forums.phpfreaks.com/topic/47000-solved-header-problem/#findComment-229255 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.