4

I'm trying to extend an old web application which uses CodeIgniter 1.7 (I know...) and am running into some trouble. I want a certain route to only be accessible via a POST request. So at the top of the function I have the following;

if ($_SERVER['REQUEST_METHOD'] != 'POST')
    die ('Wrong request method: ' . $_SERVER['REQUEST_METHOD']);

Locally, on PHP 7.0.14 with PHP's built-in web server, this works fine. In production, however, on a CPanel-managed server running PHP 5.4.25, it doesn't.

When sending a POST request to my route with Postman, I get the following;

Wrong request method: GET

PUT, PATCH, DELETE, ... requests all get recognised correctly. POST requests, however, seem to magically become GET requests.

POST data I sent with the request seems to disappear as well and is not to be found in either $_POST or $_GET.

It seems to not be related to the CodeIgniter framework however as when I call a file outside of the framework I get the same result.

Any thoughts?

RobinJ
  • 5,022
  • 7
  • 32
  • 61
  • Possibly the same answer as http://stackoverflow.com/questions/20268863/laravel4-post-unexplained-redirect-to-get (not sure it is a duplicate though). – LSerni Jan 12 '17 at 17:15
  • Any mod_rewrite rules? – Alex Blex Jan 12 '17 at 17:15
  • Also, check access logs, if there was a redirect. It's quite common to respond with 302 after processing POST requests to avoid form re-submission by page reload. – Alex Blex Jan 12 '17 at 17:22
  • Definitely check LSerni's link, was gonna suggest the same problem, but depends on specific server configuration, could get redirected to an URL **with** slash from the one without. – Vaviloff Jan 13 '17 at 09:15

1 Answers1

5

I was making requests to http://domain whcih was set up to redirect to http://www.domain, which as it turns out turns POST requests into GET requests. And Postman does not notify the user of such redirects happening.

If you're running into this problem, make sure to check whether there's any redirects happening.

I wonder why this only happens with POST requests, however, and not with PUT, PATCH, DELETE, ... requests.

Thanks to LSerni, Alex Blex and Vaviloff for pointing me in the right direction.

RobinJ
  • 5,022
  • 7
  • 32
  • 61