Jump to content
xisto Community
whistle

A Answer Of "headers Already Sent"

Recommended Posts

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:

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 Xisto. 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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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://forums.xisto.com/no_longer_exists/;, 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

Share this post


Link to post
Share on other sites

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'.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

It is very simple to set up your workplace for editing your online pages

First, get this FTP program (there are numberous more but this one is best to my opinion):
SmartFTP

When you have downloaded it, install it and configure it a bit (Basically, all you need is your cPanel login username and password, and a port to connect to (i cant remember what it is) will post the port later if needed.

Then, it is all very easy, you can download and upload files from and to the server (your hosted space) and with NotePad (simple but effective, no downloads needed aswell) you can edit anything.

If you're using SmartFTP, when you are in your webspace (within the application) just drag the file you wanna edit to your folder (on your hard drive), when thats done, open that file with an editor (Notepad) and edit wherever necessary), then save it and drag it back to your hosted webspace, it will ask you if want to overwrite the existing file, well you edited so yea overwrite ^^

thats it!

Hope it helps :ph34r:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.