3

Got a really strange problem here. When sending post requests to my PHP script

$_SERVER['REQUEST_METHOD'] 

returns "GET" instead of "POST".

It works fine for every other REST method

so this is what I get

GET -> GET
POST-> GET
PUT -> PUT
DELETE -> DELETE

It only happens on one of my servers so i'm assuming it's an apache problem and i've managed to figure out that it only happens if I add "www" to my url.

I.e

www.something.com

causes the problem but

something.com

does not

I have tested on different sites on the same server and I get the same thing so I'm assuming it's global config.

Any thoughts

revo
  • 47,783
  • 14
  • 74
  • 117
  • hmm.. what is the subdomain if the form's action? they might be different subdomain with the current page. I'm not sure if that's a problem, but it's worth the try. – thedjaney Sep 27 '13 at 11:11
  • theyre not subdomains, each of the sites i've tried has it's own primary domain. thanks for the suggestion though. – Stephen Reid Sep 27 '13 at 11:22
  • try comparing the phpinfo() output – thedjaney Sep 27 '13 at 11:29
  • phpinfo() gives the same results as above. REQUEST_METHOD is still coming back as POST for GET requests. – Stephen Reid Sep 27 '13 at 11:41
  • _“it only happens if I add "www" to my url.”_ – do you have rewriting in place that redirects these requests to the non-www version? Redirects are always followed using GET, so you would lose the POST data at this point. – CBroe Sep 27 '13 at 12:12

1 Answers1

4

As the HTTP spec says for response codes 301 and 302:

Note: For historic reasons, a user agent MAY change the request method from POST to GET for the subsequent request. If this behavior is undesired, the 307 (Temporary Redirect) status code can be used instead

A third (but unlikely) possibility is you're getting a 303 response to the initial URI. The solution is twofold:

  • Configure the clients which are under your control to POST to the canonical URI so they are not redirected at all.
  • Configure your server to redirect using 307 in this case instead of 301/302.
Community
  • 1
  • 1
fumanchu
  • 14,419
  • 6
  • 31
  • 36
  • 1
    right you put me on the right track and now I've fixed it. The problem was I didn't have www.something.com as a server alias I only had something.com. So It was forwarding instead of recognising it as a legitimate address. And then your forwarding problem was kicking in. Thanks! – Stephen Reid Sep 27 '13 at 15:05