PHP Header issue with ob
I get header problem while I use ob_start()
in the beginning of a page and ob_end_flush()
at the end. Because I use header function after some query execution.
ob_start();
include_once("header.php");
global $db;
$countstmt="SELECT COUNT(*) FROM tbl_lib_hours dh WHERE book_id IN(SELECT book_id FROM tbl_book WHERE user_id=".$_SESSION['uid'].") ";
$delHourExist=$db->query($countstmt);
if($delHourExist){
header("location:edit_delivery_hours.php");
}
....
include_once('footer.php');
ob_end_flush();
In header.php there I also added ob_start(); and in footer.php i added ob_end_flush(); , but I think that is not problem, although other pages are running with same script I write above
The error I am getting:
Warning: Cannot modify header information - headers already sent in D:xampphtdocsprojectadd_book_hours.php on line 9
I'm a bit baffled the warning message doesn't include the location of the code that caused the first content to be sent to the client. The function headers_sent() can return that location, too. So, for debugging purposes, please try
if($delHourExist)
{
if ( headers_sent($path, $lineno) ) {
echo '<pre>Debug: output started at ', $path, ':', $lineno, "</pre>n";
}
header("location: edit_delivery_hours.php");
}
Is there any space before the first <?php
?
Is there an UTF8-BOM at the beginning of the file?
There's a lot of invisible output in your code:
<?php ob_start();?> --- THERE IS A LINE RETURN HERE ---
--- SPACES OR TABS ---<?php include_once("header.php"); ?> --- LINE RETURN ---
--- AND HERE ---<?php global $db;
...
Quit starting and ending your php tags. Just do this:
<?php
ob_start();
include_once("header.php");
global $db;
...
Make absolutely sure that there is no output, and no whitespace outside of your tags before the call to ob_start(). If your error is on line 9, you've got a bunch of lines before that call that could be the problem. You may want to post all of those lines, numbered, so we can look at them carefully.
链接地址: http://www.djcxy.com/p/34682.html上一篇: “头已发送”错误取决于输出长度?
下一篇: 使用ob的PHP头部问题