header("Content-type: text/html; charset=gbk"); //發送一個前序
$a=headers_sent();
var_dump($a); //false
這裡為什麼返回false?????
回複討論(解決方案)
手冊中有人提到這個問題:
http://cn2.php.net/manual/en/function.headers-sent.php#86488
手冊中有人提到這個問題:
http://cn2.php.net/manual/en/function.headers-sent.php#86488
英語不好,看不懂,麻煩解釋一下。謝謝。
header("Content-type: text/html; charset=gbk"); flush();//重新整理輸出緩衝 var_dump(headers_sent());
header("Content-type: text/html; charset=gbk"); flush();//重新整理輸出緩衝 var_dump(headers_sent());
可以講點理論的知識嗎??
比如在什麼情況下,headers_sent返回true??
很簡單,只要有任意輸出,或者調用flush
headers_sent都會返回true
例如
header("Content-type: text/html; charset=gbk");
echo " ";
var_dump(headers_sent());
很簡單,只要有任意輸出,或者調用flush
headers_sent都會返回true
例如
header("Content-type: text/html; charset=gbk");
echo " ";
var_dump(headers_sent());
header("Content-type: text/html; charset=gbk");
echo " ";
var_dump(headers_sent()); //這裡明明是false?????????????
很簡單,只要有任意輸出,或者調用flush
headers_sent都會返回true
例如
header("Content-type: text/html; charset=gbk");
echo " ";
var_dump(headers_sent());
我懷疑你這句話不對
bool headers_sent ( [string &file [, int &line]] )
如果 HTTP 標題尚未被發送出去的話,headers_sent() 將返回 FALSE,否則返回 TRUE。如果指定了選擇性參數 file 和 line, headers_sent() 將會把 PHP 的檔案名稱以及從哪一行開始有輸出放到 file 和 line 變數中。
一旦標題已經被發送,將不能再使用 header() 函數來發送其它的標題。使用此函數至少可以避免避免與 HTTP 標題有關的錯誤資訊。另一個選擇是使用輸出緩衝。
php 預設輸出緩衝是開啟的,所以 headers_sent 總是返回假
#3 的 flush() 將輸出緩衝中的內容推出(真正輸出了),所以其後的 headers_sent 返回真