我只想知道我们是否可以更改 HTTP 响应名称,
例如 header('HTTP/1.1 500 无法连接到数据库');
还是应该是 500 Internal server error
和正文中的消息?
我找到了答案。
https://www.rfc-editor.org/rfc/rfc2616#section-6.1.1
“状态代码旨在
供自动机使用,而 Reason-Phrase 供人类使用
用户。客户不需要检查或显示 Reason-
短语。”
最佳答案
是的,header('HTTP/1.1 500 Cannot connect to database');
会起作用,请参阅 http://php.net/manual/en/function.http-response-code.php#107261 中的示例:
header($protocol . ' ' . $code . ' ' . $text);
关于php - 我们可以创建自定义 HTTP 描述吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30149863/