Output control (or output buffering) allows you to write and execute your scripts normally but send data to the web browser at selected times. The main benefit of this system is that you can call the header(), setcookie() and session_start() functions at any place in your scripts without having to worry about the "headers already sent" error message.
In our battle against the "headers already sent"error message, we are going to use several functions that are natively available to PHP:
header()-is used to send a raw HTTP header.
Syntax-( string $string [, bool $replace [, int $http_response_code]] )
setcookie() -defines a cookie to be sent along with the rest of the HTTP headers. Like other headers, cookies must be sent beforeany output from your script (this is a protocol restriction). This requires that you place calls to this function prior to any output, including <html>and <head>tags as well as any whitespace.
session_start() -creates a session or resumes the current one based on the current session id that's being passed via a request, such as GET, POST, or a cookie.
Syntax– session_start()
ob_start()-This function will turn output buffering on. While output buffering is active, no output is sent from the script (other than headers). Instead, the output is stored in an internal buffer.
Syntax– ob_start()
ob_end_flush() -This function will send the contents of the topmost output buffer (if any) and turn this output buffer off. If you want to further process the buffer's contents you have to call ob_get_contents()before ob_end_flush()as the buffer contents are discarded after ob_end_flush()is called.
Syntax– ob_end_flush()
ob_end_clean() -This function discards the contents of the topmost output buffer and turns off this output buffering. If you want to further process the buffer's contents you have to call ob_get_contents()before ob_end_clean()as the buffer contents are discarded when ob_end_clean()is called.