warning: cannot modify header information - headers already sent by 的原因 我的php程序调用了header(location: www.baidu.com );函数, 运行后出现出现 warning: cannot modify header information - headers already sent by 的页面警告。 发现原来是
warning: cannot modify header information - headers already sent by 的原因
我的php程序调用了header(location:www.baidu.com);函数,
运行后出现出现 warning: cannot modify header information - headers already sent by 的页面警告。
发现原来是我的php.ini里面的配置的问题,
默认的php.ini文件中,output_buffering指令选项的默认值为off。
把它设为4096就解决了显示提示warning错误的提示。.
php.ini 文件对 output_buffering指令选项做了详细说明如下:
94 ; output buffering allows you to send header lines (including cookies) even 95 ; after you send body content, at the price of slowing php's output layer a 96 ; bit. you can enable output buffering during runtime by calling the output 97 ; buffering functions. you can also enable output buffering for all files by 98 ; setting this directive to on. if you wish to limit the size of the buffer 99 ; to a certain size - you can use a maximum number of bytes instead of 'on', as 100 ; a value for this directive (e.g., output_buffering=4096). 101 #output_buffering = off 102 output_buffering = 4096
最后,重启,使修改后的配置文件生效。
在linux下,
如果因php命令行而修改php.ini 则不需要重启;
如果因apache而修改php.ini,则需要重启apache服务;
总之,就是那个服务使用了php,就重新启动该服务,就可以了。