By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,304 Members | 1,253 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,304 IT Pros & Developers. It's quick & easy.

problem with headers already sent!

vinci
P: 62
hey guys!

can u help with this!

i uploaded my files into a web hosting site, after that, i made all the necessary changes but when i tried to load the page a warning is being displayed:

"Warning: Cannot modify header information - headers already sent by (output started at /home/www/ycoppettenz.awardspace.com/index.php:8) in /home/www/ycoppettenz.awardspace.com/index.php on line 17"

what should i do??? by the way, i am using php mysql...

also, where can i find a site that is giving a free domain?? hehehe... my website is only a subdomain of awardspace because it is free...hehehe

thanks in advance!!!
Feb 12 '07 #1
Share this Question
Share on Google+
4 Replies


Motoma
Expert 2.5K+
P: 3,235
hey guys!

can u help with this!

i uploaded my files into a web hosting site, after that, i made all the necessary changes but when i tried to load the page a warning is being displayed:

"Warning: Cannot modify header information - headers already sent by (output started at /home/www/ycoppettenz.awardspace.com/index.php:8) in /home/www/ycoppettenz.awardspace.com/index.php on line 17"

what should i do??? by the way, i am using php mysql...

also, where can i find a site that is giving a free domain?? hehehe... my website is only a subdomain of awardspace because it is free...hehehe

thanks in advance!!!
DynDNS is a good place to get a free domain.

Your PHP file is trying to send headers, however, headers have already been sent on the page (i.e. you have delivered content to the page, therefore you can no longer send headers).

If you have no idea what I am talking about, post some code and I will point it out.
Feb 12 '07 #2

ronverdonk
Expert 2.5K+
P: 4,258
I will show the text of an article by wildteen88, june 2006, who can explain this a lot better then I can.

The reason why you are getting this message is because you have may have/be:
  • Whitespace before the opening php tag <?php
  • Outputting something to the browser before you use session_start, header, setcookie etc
session_start, setcookie, header and a few other functions write header information to the web server/browser what to do. Such as when you use session_start it requests the browser to create a cookie which stores the PHPSESSID.

If you have output before you use these functions then they are unable to send new header information as it has already been sent in the form text/html, and so you get the headers already sent error message.

You can easily find the source of the problem by looking at the error message. As the answer is actully in there, but most people dont notice it as they may not understand what the error means. So lets take this error message as an example:

Warning: Cannot modify header information - headers already sent by (output started at C:\server\www\test.php:6) in C:\server\www\test.php on line 8
Now PHP has given us a clue here as it has told use where the output has started! Have look where it says output started at and it gives you the full path to the file and the line number. Now the line number that it stats is not usually where the output has started but where the output has ended, becuase the output could be above that line.
So lets look at test.php:
Expand|Select|Wrap|Line Numbers
  1.  1 <html>
  2.  2 <head>
  3.  3 <title>Header test</title>
  4.  4 </head>
  5.  5 <body>
  6.  6 <?php
  7.  7
  8.  8 header("Location: http://www.google.com");
  9.  9
  10. 10 ?>
  11. 11 </body>
  12. 12 </html>
As you can see line 6 is the opening PHP tag (< ?php) this isn't the output but look above that line you'll notice it has some HTML code. This html code is the cause of the error!

So when you get this error message again look for the clue where it says output started at and goto the file and line number it says. Look above the line number and find where your output is located to.

Hope that helps you understand why your are getting this error message. (Thanks to wildteen88)

Ronald :cool:
Feb 12 '07 #3

100+
P: 136
Hi,

If you use any plain html code, whitespace character or php code that can generate output before calling header() function that will cause the error headers already sent......

As response you can't send header more than once. So any output prior to calling header() function will pass the header as response. Henceforth header() function will the error.

Susen
Feb 13 '07 #4

ronverdonk
Expert 2.5K+
P: 4,258
Hi,

If you use any plain html code, whitespace character or php code that can generate output before calling header() function that will cause the error headers already sent......

As response you can't send header more than once. So any output prior to calling header() function will pass the header as response. Henceforth header() function will the error.

Susen
What does this add to the previous post? Or do I miss something?

Ronald :cool:
Feb 13 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.