Jump to content

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/47000-solved-header-problem/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/47000-solved-header-problem/#findComment-229208
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/47000-solved-header-problem/#findComment-229213
Share on other sites

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().

Link to comment
https://forums.phpfreaks.com/topic/47000-solved-header-problem/#findComment-229219
Share on other sites

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

 

Link to comment
https://forums.phpfreaks.com/topic/47000-solved-header-problem/#findComment-229221
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/47000-solved-header-problem/#findComment-229224
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/47000-solved-header-problem/#findComment-229255
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.