[PHP] 意外的 session_start() 錯誤
1
Warning: session_start(): Cannot send session cache limiter -
headers already sent (output started at D:\test.php:1)
in D:\test.php on line 2
有的時候出現這種錯誤不見得是故意的,但是程式碼很長的時候就很難去注意到最上面不小心多出一個東西。
如果我只貼程式碼最上面的一段,錯誤就很明顯了。
1
<?
session_start();
?>
可能在開檔案的時候鍵盤壓到了 ,所以在最開頭的地方多了個 1。但是在程式碼一大片的時候,大概不會有人注意到最上面多了一個字,以致於 session_start(); 發生錯誤。
至於為什麼 session_start(); 前不能先輸出文字呢?
有興趣的人就看看 PHP 官方說明吧:
session_start() will register internal output handler for URL rewriting when trans-sid is enabled. If a user uses ob_gzhandler or like with ob_start(), the order of output handler is important for proper output. For example, user must register ob_gzhandler before session start.
http://www.php.net/session_start