I had a similar problem and I solved it removing blank spaces in source code.
Specifically, the error occurs when an answer is send to the client prematurely. This can happen on accident when you have whitespace outside of the
<?php ?>-tags. One way to mostly prevent this mistake is by simply not having a
?> at the end of the document.