解决Warning: Cannot modify header information - headers already sent by的方法-Discuz教程下载

解决Warning: Cannot modify header information - headers already sent by的方法

开通本站Svip会员,全站资源免费下
在后台管理或者有时候在论坛,点击一个页面,页顶会出现
Warning: Cannot modify header information - headers already sent by....
这类语句,造成这个原因是因为setcookie语句的问题。

cookie本身在使用上有一些限制,例如:
1.呼叫setcookie的敘述必須放在<html>標籤之前
2.呼叫setcookie之前,不可使用echo
3.直到網頁被重新載入後,cookie才會在程式中出現
4.setcookie函數必須在任何資料輸出至瀏覽器前,就先送出
5.……
基於上面這些限制,所以執行setcookie()函數時,常會碰到"Undefined index"、"Cannot modify header information - headers already sent by"…等問題,解決"Cannot modify header information - headers already sent by"這個錯誤的方法是在產生cookie前,先延緩資料輸出至瀏覽器,因此,您可以在程式的最前方加上ob_start();這個函數。这样就可以解决了。

全部评论 0

您需要登录后才可以回帖 立即登录
登录
0
0
0
返回顶部