问题描述
很简单的问题:这两个PHP(版本5+)头文件调用中的哪一个是最好的?标题('Not Modified',true,304);
header('HTTP / 1.1 304 Not Modified');
我很确定第一个是多数的,但只是好奇PHP会修复第二个,如果在HTTP 1.0下......
谢谢!
$ b 编辑:其中一个头文件在我的Web主机上崩溃了PHP。后续问题:
我会使用这个:
header($ _ SERVER ['SERVER_PROTOCOL']。'304 Not Modified',true,304);
包含请求中使用的协议,例如 HTTP / 1.0
或 HTTP / 1.1
。
编辑我不得不承认我的建议毫无意义。经过几次测试,我发现如果第一个参数是一个有效的,PHP将使用该状态行,而不管第三个参数是否给出了第二个状态码。第二个参数(文档名称替换)也是无用的,因为不能有多个状态行。所以第二个和第三个参数在这个调用中只是多余的:
header($ _ SERVER ['SERVER_PROTOCOL']。'304 Not Modified',true,304 );
使用这个代替:
header($ _ SERVER ['SERVER_PROTOCOL']。'304 Not Modified');
Pretty simple question: which one of these two PHP (version 5+) header call is the "best"?
header('Not Modified', true, 304);
header('HTTP/1.1 304 Not Modified');
I'm pretty sure the first one is the most polyvalent one, but just curious if PHP would "fix" the second one if under HTTP 1.0...
Thanks!
Edit: One of these header crashes PHP on my Web host. Follow-up question at:PHP header() call "crashing" script with HTTP 500 error
I would use this one:
header($_SERVER['SERVER_PROTOCOL'].' 304 Not Modified', true, 304);
$_SERVER['SERVER_PROTOCOL']
contains the protocol used in the request like HTTP/1.0
or HTTP/1.1
.
Edit I have to admit that my suggestion is senseless. After a few tests I noticed that if the first parameter is a valid HTTP status line, PHP will use that status line regardless if and what second status code was given with the third parameter. And the second parameter (documentation names it replace) is useless too as there can not be multiple status lines.
So the second and third parameter in this call are just redundant:
header($_SERVER['SERVER_PROTOCOL'].' 304 Not Modified', true, 304);
Use just this instead:
header($_SERVER['SERVER_PROTOCOL'].' 304 Not Modified');
这篇关于在PHP中使用头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!