我需要发送"500内部服务器错误“从PHP脚本在某些条件下。该脚本应由第三方应用程序调用。该脚本包含两个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
这样的错误会被get服务器记录下来吗?
https://stackoverflow.com/questions/4162223
复制相似问题