PHP的header()函数中的CRLF(\ r \n)

1 php newline http-headers

为什么/何时必须在PHP的标题末尾使用CRLF?这是一个例子(它不一定正确):

header("method: POST\r\n");
header('Host: '.get_option('transact_url')."\r\n");
header('Content-type: application/x-www-form-urlencoded');
header('Content-length: '.strlen($transaction)."\r\n");
header($transaction."\r\n\r\n");
header("Connection: close\r\n\r\n");
header("Location: ".$key_client_url."\r\n");
Run Code Online (Sandbox Code Playgroud)

hal*_*dan 5

你永远不应该在header()内部进行手动换行.当前的实现删除了换行符,因此您可以安全,但这可能在将来发生变化(尽管没有理由应该更改它).

  • @nush他说不是"你*可以*省略",而是"你**永远不应该使用它".你看到这些代码是因为一些程序员没有足够的知识.这么简单的解释. (2认同)