Header already sent![solved]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
persiangulf
Forum Commoner
Posts: 30
Joined: Tue Jan 29, 2008 12:04 pm

Header already sent![solved]

Post by persiangulf »

Yes,again this problem and this warning "header already sent". But this time I do not know why because the error occur in the first line of script(I can swear that I did not echo anything!). I use AJAX in my script and it is the first time that I front this problem.
I send the url and the data by AJAX to the php script that parse and return the result but in the first line where I include(by require_once) a script, I front a warning and be sure that there is no echo or something like this before errored line!
Last edited by persiangulf on Tue Jan 29, 2008 12:55 pm, edited 1 time in total.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Header already sent!

Post by Christopher »

Make sure there are no space or newline characters characters before the <?php and after the ?> in any files. In files that contain only PHP, the ?> in not required and removing it can eliminate the problem of having hidden space or newline characters at the end of a file.
(#10850)
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Re: Header already sent!

Post by JAM »

Code: Select all

error_reporting(E_ALL);
You got that at the top of the page you are calling. Making sure you catch all errors that is.

Also, it's not only echo's/print's that gives you these problems. A common issue is if you have a blank row before the first <?php or if the script generates an error that's not displayed on the page itself but within the code. The later you can usually find by a 'View Source' at the generated page.
persiangulf
Forum Commoner
Posts: 30
Joined: Tue Jan 29, 2008 12:04 pm

Re: Header already sent[solved]!

Post by persiangulf »

Yes,I solved it!But the problem was not the thing that you said.The problem was the type of encoding the saved script!Your advice helped me a lot because I said to myself let me see if the encoding is not problem because I use Dreamweaver under Linux and by wine(I said to myself may be the default encoding make this problem).
Thanks a lot because of your big advice.(add encoding problem to your list :lol: )
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Re: Header already sent!

Post by JAM »

'C) None of the above...'-problems like this is usually found by just discussing the issue. It's hard to spot errors if you don't think out of the box. :wink:
Glad you worked it out.
Post Reply