How to print Error 405 Method not allowed to users
Asked Answered
S

1

6

I'm working on iOS UDID retrieval script and sadly been stuck in a tiny problem. As you may know, to retrieve iOS UDID, users must install a profile on iOS device. Afterward, device respond to the link which is defined into the profile. If user open the retrieval link directly, will get Error 405 Method not allowed. same as the following links: http://get.udid.io/retrieve/ and http://license.if0rce.com/connect/retrieve

The code in /retrieve/index.php is:

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

I may set a custom error by adding:

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    header("HTTP/1.0 405 Method Not Allowed");
exit(); }

But it's not the professional way. I would like user get an error exactly the same as the mentioned links.

Any ideas?

Appreciate your help :)

Schrock answered 17/5, 2014 at 23:36 Comment(2)
You must be joking, tagging this with information-retrieval … (removed)Aliaalias
Note that according to RFC 2616, a 405 response "MUST include an Allow header containing a list of valid methods for the requested resource."Sisera
H
11

Apache isn't set up to action error documents for PHP set status codes. In 'custom-msg.php' you can Add message you want to show.

if ($_SERVER['REQUEST_METHOD'] == 'GET') {
header("HTTP/1.0 405 Method Not Allowed"); 
include 'custom-msg.php';
exit(); }
Hydrodynamic answered 17/5, 2014 at 23:47 Comment(3)
Thanks. Did they do the same job?Schrock
You must also include an Allow header with a 405 response (section 14.7): w3.org/Protocols/rfc2616/rfc2616-sec14.htmlHomeward
Why not just use http_response_code(405) instead of header("HTTP/1.0 405 Method Not Allowed")?Encyclopedia

© 2022 - 2024 — McMap. All rights reserved.