为什么不是';php中的t header()函数抛出错误?

为什么不是';php中的t header()函数抛出错误?,php,http-headers,Php,Http Headers,我将header函数放在一些输出之后,但仍然被发送到指定的位置 <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> hello <?php echo 'hello'; ?> <?ph

我将header函数放在一些输出之后,但仍然被发送到指定的位置

 <!doctype html>
 <html lang="en">
 <head>
    <meta charset="UTF-8">
    <title>Document</title>

 </head>
 <body>
    hello
    <?php echo 'hello'; ?>
    <?php header('Location: http://www.google.com/'); ?>
 </body>
 </html>
为什么我仍然被重定向到google.com

 <?php ob_end_flush(); 
echo 'hello';
 header('Location: http://www.google.com/'); ?>

在php.ini中,您将发现如上所示。。在整个php.ini文件中查找关键字“output\u buffering”,它应该在某个地方。。要以其他方式检查,请使用
phpinfo()
在任何php页面中运行该页面,您将发现
output\u buffering
,因为“1”表示它处于打开状态。。因此,通过关闭它,您可以终生或暂时停止它,您可以使用
ob_end_flush()正如我前面提到的。

在编辑php.ini后是否重新启动了服务器?可能是我没有编辑任何内容的副本,就是这样always@CyrilBeeckman重复的答案是询问为什么不重定向。我的问题是为什么重定向?哦,对不起,你在本地吗?ini文件中输出缓冲区的配置一直在那里,我没有编辑它。你在本地使用WAMP吗?XAMPP的默认值似乎是
output\u buffering=4096
。问题中引用的“设置”来自文件后面的“快速参考”部分-它们不是文件后面出现的实际设置(如上所述)。另见
 <?php ob_end_flush(); 
echo 'hello';
 header('Location: http://www.google.com/'); ?>
; Output buffering is a mechanism for controlling how much output data
; (excluding headers and cookies) PHP should keep internally before pushing that
; data to the client. If your application's output exceeds this setting, PHP
; will send that data in chunks of roughly the size you specify.
; Turning on this setting and managing its maximum buffer size can yield some
; interesting side-effects depending on your application and web server.
; You may be able to send headers and cookies after you've already sent output
; through print or echo. You also may see performance benefits if your server is
; emitting less packets due to buffered output versus PHP streaming the output
; as it gets it. On production servers, 4096 bytes is a good setting for performance
; reasons.
; Note: Output buffering can also be controlled via Output Buffering Control
;   functions.
; Possible Values:
;   On = Enabled and buffer is unlimited. (Use with caution)
;   Off = Disabled
;   Integer = Enables the buffer and sets its maximum size in bytes.
; Note: This directive is hardcoded to Off for the CLI SAPI
; Default Value: Off
; Development Value: 4096
; Production Value: 4096
; http://php.net/output-buffering
output_buffering = On