I do an ajax POST request to my own PHP backend. IT works on my developer machine and it works on the production machine but it does not work on the stage machine. All with the same data. So I guess it must have something to do with the PHP configuration.
The request looks completly fine in developer tools
What is the php $_SERVER[‘REQUEST_METHOD’] value? I suspect the server is being reached via a redirect, so it’s getting a get method request w/o any post data.
No, the server is reached directly without any proxy, or similar. Also it’s only this one post request. I do hundred of other post requests the same way and they work. So there must be something special on this data but I do not know what.
When I replace the data value with an empty object it works also. But the data is just a json encoded object. So I do not know why it can break the post values.
Is there a request limit? Maybe you’re hitting quota during this instance? I guess better question is, are you running the same request multiple times repeatedly or is this a single request per few seconds situation?
All three server have same config with php8.2 and Apache 2.6. it works on two servers but not on the third. All requests work only this one does not work. It must be a combination of these special request and the config of the server. max_post_size is set to 20M. So that not the reason
As @Zensei mentioned, you need to take a look at your network requests. Chances are you’re getting a 302 to your POST request, and the server is then sending a GET request to the same URL…hence you have no POST data.
First thing you ALWAYS do when you have an error is look in the logs 9/10 you’ll solve the problem this way. When you get a chance tune up your logs to make sure any messages being send are verbose.
As a check, echo the $_SERVER[‘REQUEST_METHOD’] before the very first line of code, and die. If it is GET, the redirect is happening before it touches the code, which means the issue is possibly a server issue.
One more thing to rule out…I’ve had this happen in Edge, then when switching to Chrome all was fine. Switching back to Edge the problem reappeared. Turn off all browser extensions and retest.
Not necessarily. While I agree you should always check your logs, what I quoted isn’t always true. A 302 redirect doesn’t necessarily mean it’s a bad thing. The issue @Thallius is having doesn’t pertain to network issues.
The error is stating that the key token doesn’t exist within the $_POST array. Now I wouldn’t think Thallius wouldn’t know the difference between POST and GET. So we can rule out the use of GET and POST methods in the form. We’ve already ruled that there is no request limit with my question since what I was trying to get at is, if this is using a 3rd party API, there most likely will be a quota limit to prevent DDOS.
The next logical question would be what are these payloads coming in as? JSON or www-form-urlencoded? I’ve done something similar multiple times where my APIs are using php://input and expecting it to be in a JSON format, but I’m sending data via www-form-urlencoded and I don’t see indexes I’m expecting. Or it could just be as simple as what @rpkamp is suggesting and could just be a misconfiguration in the php.ini file.
The data is send as www-form-urlencoded. That’s why I json encode the value of data before sending manually as I can’t sent an object otherwise.
Is there any limitation on the size of the form values?
This does happen sometimes, especially (from my own anecdotal experience) if PHP is being loaded as a FastCGI module in IIS. I’ve found i had to completely shutdown and restart the IIS instance.