Hi
I am getting this very error.....
Cannot modify header information - headers already sent by (output started at C:\Program Files\xampp\htdocs\gallery2\examples\live-excel.php:36)
I have tried ob_start(); but of no use. It did not work....
can someone give the solution.??
Thanks in advance
cheers
Prati
Output buffering is not supported on all servers. (Though most do).
To test if you have Output buffering support try this on a php page on your server::
<?php
ob_start();
echo 'dummy content';
if (headers_sent() || !ob_get_length()) {
echo 'Your sever does not support output buffering';
} else {
echo 'Output buffering supported';
ob_clean();
}
?>
If your server does support output buffering, then it may be that the buffer is being dumped prematurely before you're sending your headers. This could be happening if you're using flush() or ob_flush() before you use header().
When you use the header() function, you should always check if headers have been sent or not...
Here's an example function to use in place of header():
function safe_header($str) {
if (!headers_sent()) {
header($str);
return true;
}
return false;
}
What way you get a return of false if the header could not be sent.
Example Use:
if (safe_header('Location: login.php')) {
die;
} else {
echo '<script>location = 'login.php';</script>';
echo 'Please <a href="login.php">Login</a>';
die;
}
Note that if headers are already sent then you cannot send any more headers or you'll get the error you're getting. So instead you can send some content such as JS to try and redirect the page. If the user does not use JS, then you'll have to fallback to a link.
digital-ether
Nearly a Posting Virtuoso
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
Peace, Could I know what is the function ob__start(); ?
Thanks.
Best regards.
Heres the reference at php.net: http://www.php.net/ob_start
ob_start() is part of the output control functions in PHP. See: http://www.php.net/manual/en/ref.outcontrol.php
Calling ob_start() begins the buffer of output that is normally sent to HTTP (with PHP on a webserver).
Do to the HTTP specification, you cannot send any HTTP Headers after you have sent some HTTP Content. ob_start() allows you to have the HTTP Content placed in a buffer, so that you can send HTTP headers at any time. Then at the end of your PHP script, call ob_end_flush() which will flush the HTTP Content.
Edit: Looks like php_coder got to your question first. :)
digital-ether
Nearly a Posting Virtuoso
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101