Jul 25, 2008

A Answer Of "headers Already Sent"

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming
Pages: 1, 2

free web hosting

A Answer Of "headers Already Sent"

whistle
I install a php script on my trap 17 host. Everything is perfect before I test the script. When I login, it suddenly displays as following:

QUOTE
Warning: Cannot modify header information - headers already sent by (output started at /home/whistle/public_html/center/counter/config.php3:20) in /home/whistle/public_html/center/counter/Change.php3 on line 20


I watch the config.php3, nothing is incorrect. Then I look at the Change.php3, there is nothing wrong. Then I try to find the history topics in the Trap17. It is interesting, I am not the only one in the same trouble. But I can't not find the correct solusion.

There is one who suggests to check whether there is any space before the header() function. I ensure there is no space between <? and ?>, but I found there is two blank line after the "?>" in the config.php. They are blank lines, of course I can't find anything. That's why everything goes wrong. But why this happens?

I recall what I did. I loged into my cpanel, then use the file manager. Afterwards, I chosen the config.php and edited it in the new pop up browser with a default editor in it, then I saved the file. I did not do anything stupid. Finally I find the editor is the trouble maker. Each time I save, It appends another line in the end of my file. It is terrible and stupid tool. If you are a newbie like me, I think you are lucky to read this topic. Yes, you are lucky, because no one ever tell me this and waste me 3 hours. I am lucky too, eventually I find what the problem is. Only 3 hours waste, I almost gave up.

 

 

 


Reply

bureX
Some editors (such as yours) may use different text formatting (such as UTF-8) and may, sometimes, add some invisible characters that PHP sees as characters that have already been outputted to the browser! Really stupid, indeed...

So, be careful while choosing your PHP code editor, or just use Macromedia Dreamweaver! If you choose to stick with your current code editor, make sure that you have chosen the right text formatting.

Reply

biscuitrat
Also, get rid of blank lines beyond the ?> - that always made my wordpress blog mess up.

Reply

Hamtaro
Cpanel's file manager does that to me all the time, and it caused me trouble a while back when I started learning PHP. Now, I just use Notepad (or sometimes, NoteTab). Even Notepad can sometimes also add extra characters (hidden, of course) to files (this happens very rarely to me). Anyway, I'd recommend NOT using the Cpanel editor for PHP scripts like that. It would probably just be easier to make the script on some other editor, then upload via FTP. I've wondered a few times why it adds those extra lines (the Cpanel editor, that is). Anyway, I'm glad you figured it out on your own (even though it did take you a while).

Reply

HmmZ
CODE
Warning: Cannot modify header information - headers already sent by (output started at /home/whistle/public_html/center/counter/config.php3:20) in /home/whistle/public_html/center/counter/Change.php3 on line 20


1: Ensure there are no blank lines before the error
2: Make sure session_start() or cookie setups is/are the very first thing(s) after <?php, meaning it MUST be on line 2
3: Make sure the header is written correctly, it needs a full url and not just "change.php" , but "http://www.your-domain.com/change.php", in some cases, it's not necessary, but it gives you extra insurance that it isnt that
4: If the above dont solve your problem reply, ill dig in further..

Hope it helps

Reply

Spectre
All data sent to a client from a webserver is prefixed with headers informing the client of important information regarding the data (or chunk of data). These can only be sent once - and it occurs when the first lot of output is sent to the client, regardless of what it is. If you get a 'headers already sent' error, it means that some form of output has been sent to the client, either from PHP directly or by the webserver itself (such as, for example, having blank lines before the opening <? tag in a PHP script or having HTML before the PHP code block).

Check line 20 of '/center/counter/config.php3'.

Reply

OpaQue
I havent gone through the replies you recieved above, but this is a very common error.

Headers can be sent only before any output is sent to the client. You must ensure this so that you can easily avoid this error.

LEAVE no space,

before <?, Because, if this is your starting file, then you will get this error.

Now, space after ?> Does not make much sense, but it is good if you dont include spaces after. Because, suppose, you are including a particular file A into B, and if A has space after ?>, then you will definately get the error again.

Create Functions for ERRORs and ALERTS. We usually have a tendency to directly use Print statement. But then, once we do that, we start out the output and we never know, where the output started, if your script is very big. Embedding them in a function will help you pinpoint, where your code is giving output from.

If possible, Create a output class for displaying output to the user. And pass everything to this class. You can then create functions which will buffer this output and give you more control over your script. (This can be achieved using a simple variable too, but it is not soo flexible.)

 

 

 


Reply

Saint_Michael
i notice that you have the php3 as your file just get rid of the 3 and that might help on top of what everyone else has said.

Reply

whistle
I am a novice in php programming. I don't know how to edit programs online. The only tool is the online editor the web hosting gives me. I never notice it adds a new bland line whenever I open a file. It is just like that someone throw garbage to my place and I am not acknowledged. It arises my another question, can I get better tools to edit my programs online?

Reply

Spectre
Personally, I would recommend you use a text editor to modify your scripts locally, then test them on your machine before uploading. If you use Windows, Notepad should do the trick or on *nix, vi should work ok. Keep in mind that a text editor is very different from a word processor, and you obviously don't want the additional formatting a word processor would add to the script.

Reply

Latest Entries

sobhan
This is just becaus you are adding cookies or sessions after 'head' in HTML. I had same problem. I gave cookies before head, and my php script worked.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Pages: 1, 2

Searching Video's for answer, headers
advertisement



A Answer Of "headers Already Sent"



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE