gpt4 book ai didi

php - 在使用它之前是否必须检查 $_SERVER 变量中是否存在 'REQUEST_METHOD'?

转载 作者:可可西里 更新时间:2023-11-01 13:13:31 25 4
gpt4 key购买 nike

在实际使用 $_SERVER['REQUEST_METHOD'] 之前,我是否必须检查 $_SERVER 变量是否具有键 REQUEST_METHOD

也就是说,总是检查数组变量中是否存在某个键是否过于防御,如 $_SERVER

最佳答案

PHP 手册 says the following关于 $_SERVER 变量:

There is no guarantee that every web server will provide any of these; servers may omit some, or provide others not listed here. That said, a large number of these variables are accounted for in the » CGI/1.1 specification, so you should be able to expect those.

CGI/1.1 specification有以下要说的:

The REQUEST_METHOD meta-variable MUST be set to the method which
should be used by the script to process the request, as described in
section 4.3.

The Request Method, as supplied in the REQUEST_METHOD meta-variable, identifies the processing method to be applied by the script in
producing a response. The script author can choose to implement the
methods most appropriate for the particular application. If the
script receives a request with a method it does not support it SHOULD reject it with an error (see section 6.3.3).

如果您不进行任何 CLI 开发,则可能没有必要检查其是否存在,并且该脚本只会从 Apache 等服务器运行。为了安全起见,您可能会这样做,但没有必要这样做。

关于php - 在使用它之前是否必须检查 $_SERVER 变量中是否存在 'REQUEST_METHOD'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14046148/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com