I use the same php script for including and for ajax loading. It is some random catalog items which are loaded with the page and can be loaded with ajax. I need to use header()
function there only if it is loaded via ajax.
When I use header function and the output already started I get php warning about it. How does php know that output already started? What is the best way to determine that, and not to call header function?
Thanks.
http://php.net/manual/en/function.headers-sent.php
// If no headers are sent, send one
if (!headers_sent()) {
header('...');
exit;
}
There's an easy built-in for that:
if (!headers_sent()) {
header('Your header here');
}
Not much more to add :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With