Home > php教程 > php手册 > body text

setcookie语句的问题

WBOY
Release: 2016-06-13 10:34:54
Original
1107 people have browsed it

出现的错误提示:

Warning: Cannot modify header information - headers already sent by

解决办法:

打开php_ini,搜索output_bufferfing,把前面的分号去掉,把off修改为on,或者设置一个数值。就可以了。

这类语句,造成这个原因是因为setcookie语句的问题。

cookie本身在使用上有一些限制,例如:
1.呼叫setcookie的?述必?放在标签之前
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();这个函?。这样就可以解决了。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!