如何打印错误405方法不允许用户

时间:2014-05-17 23:36:40

标签: php ios udid http-status-code-405

我正在开发iOS UDID检索脚本,遗憾的是我遇到了一个小问题。 您可能知道,要检索iOS UDID,用户必须在iOS设备上安装配置文件。之后,设备响应定义到配置文件中的链接。如果用户直接打开检索链接,将不允许使用错误405方法。与以下链接相同: http://get.udid.io/retrieve/http://license.if0rce.com/connect/retrieve

/retrieve/index.php中的代码是:

<?php
$data = file_get_contents('php://input');
file_put_contents("data.txt", $data);
?>

我可以通过添加:

来设置自定义错误
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    header("HTTP/1.0 405 Method Not Allowed");
exit(); }

但这不是专业方式。我希望用户得到与上述链接完全相同的错误。

有什么想法吗?

感谢您的帮助:)

1 个答案:

答案 0 :(得分:5)

Apache未设置为PHP集状态代码的操作错误文档。 在'custom-msg.php'中,您可以添加要显示的消息。

if ($_SERVER['REQUEST_METHOD'] == 'GET') {
header("HTTP/1.0 405 Method Not Allowed"); 
include 'custom-msg.php';
exit(); }