The above error message is displayed when some content has already been sent to the web browser and then a header is set for e.x. setting a cookie etc. Headers must be set before sending any content which is the reason for the error.
While it is best to ensure all headers are set before sending any content, sometimes it can be simpler to just use output buffering which will eliminate the error message. When output buffering is enabled, all the headers will be sent but the content will only be sent either at the end of the script or when explicitly done by the script.
By default output is not buffered by PHP and the contents of the script is sent to the browser in small groups as it is created. PHP's output buffering functions buffer the output giving control over when content is sent, allowing it to be compressed and allowing a mixture of headers and content to be coded.
Output buffering allows you to send header lines (including cookies) even
after you send body content. You can enable output buffering during runtime by calling the output buffering functions.
To enable output buffering one can add the following to the start of the PHP script:
You can also enable output buffering for all files by setting this directive to On.
in
php.ini you can enable it as below
To limit the size of the buffer to a certain size -you can use a maximum number of bytes instead of 'On', as a value for this directive.