如何从 PHP 脚本发送 500 内部服务器错误错误编辑
2022-08-30 07:59:40
在某些情况下,我需要从PHP脚本发送“500内部服务器错误”。该脚本应由第三方应用程序调用。该脚本包含几个语句,我需要为其发送响应代码而不是通常的。第三方脚本将在某些条件下重新发送请求,包括未收到响应代码。die("this happend")
500 Internal Server Error
200 OK
200 OK
问题的第二部分:我需要像这样设置我的脚本:
<?php
custom_header( "500 Internal Server Error" );
if ( that_happened ) {
die( "that happened" )
}
if ( something_else_happened ) {
die( "something else happened" )
}
update_database( );
// the script can also fail on the above line
// e.g. a mysql error occurred
remove_header( "500" );
?>
我只需要在执行最后一行后发送标头。200
编辑
题外话:我可以发送奇怪的500个标头,例如:
HTTP/1.1 500 No Record Found
HTTP/1.1 500 Script Generated Error (E_RECORD_NOT_FOUND)
HTTP/1.1 500 Conditions Failed on Line 23
Web服务器会记录此类错误吗?