How to send 500 Internal Server Error error from a PHP script(如何从 PHP 脚本发送 500 Internal Server Error 错误)
问题描述
I need to send "500 Internal Server Error" from an PHP script under certain conditions. The script is supposed to be called by a third party app. The script contains a couple of die("this happend")
statements for which I need to send the 500 Internal Server Error
response code instead of the usual 200 OK
. The third party script will re-send the request under certain conditions which include not receiving the 200 OK
response code.
Second part of the question: I need to setup my script like this:
<?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" );
?>
I need to send 200
header only after the last line has been executed.
Edit
A side question: can I send strange 500 headers such as these:
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
Will such errors get logged by the webserver?
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
这篇关于如何从 PHP 脚本发送 500 Internal Server Error 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从 PHP 脚本发送 500 Internal Server Error 错误


基础教程推荐
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01