标题如何在PHP中工作? [英] how does the header work in php?

查看:69
本文介绍了标题如何在PHP中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过php.net网站,它有一个标题的例子,它说会给我错误。我复制了它,并在WAMP上执行,但它没有显示任何错误,但是重定向到了该网站。

 < HTML> 
<?php
/ *这应该会给出错误(但它不会!)。注意上面的输出
*,它位于header()调用之前* /
header('Location:http://www.example.com/');
?>

只是想知道,如果它对我的WAMP是正确的行为,或者它的错误,或者如果我有任何特定的设置在php.ini文件中激活这个工作!!!。



谢谢,
Tanmay

解决方案

听起来好像你已经启用了output_buffering。

http://php.net/manual/en/outcontrol.configuration.php

标准配置应该是错误的,因为数据已经输出,并且标头需要先到达。输出缓冲将允许标题在其他输出后出现在代码中,但由于缓冲区的原因,它仍会首先输出标题。


Going through the php.net site, it had an example for header, which says would give me error. I copied it, and executed on on WAMP, but it didn't showed me any error, but did redirect to the site.

<html>
<?php
/* This should give an error (but it doesn't!). Note the output
 * above, which is before the header() call */
header('Location: http://www.example.com/');
?>

Just wanted to know, if its a right behavior on my WAMP, or its an error, or if I have any particular settings active in php.ini file which is making this work!!!. Let me know if anyone needs my php.ini to be copied here!!

Thanks, Tanmay

解决方案

It sounds like you have output_buffering enabled.

http://php.net/manual/en/outcontrol.configuration.php

Standard configuration would be to error because data has already been output, and headers need to come first. Output buffering would allow headers to appear in code after other output, but it would still output the headers first due to the buffer.

这篇关于标题如何在PHP中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆