POST Parameters Are Ignored in PHP While GET Works: The $_REQUEST Gotcha
You are likely encountering a classic misconfiguration where your server-side code fails to receive POST data despite it appearing correctly in the client tool. In your specific scenario, sending URL parameters (the query string) works perfectly, but switching to x-www-form-urlencoded body data results in an empty payload in your script, with only the session ID (PHPSESSID) showing up in $_REQUEST.
This behavior usually indicates that the HTTP request is not reaching your PHP application's processing logic as a standard form submission. Instead, the server is treating the incoming request differently, often routing it to a static file handler or an error page before the PHP interpreter can process the $_POST superglobal.
The Nature of $_REQUEST and $_POST
To understand why this happens, we must look at how PHP aggregates data. The $_REQUEST array is a merge of $_GET, $_POST, and $_COOKIE. If you see only PHPSESSID in $_REQUEST when sending POST data, it implies that $_POST is empty.
When you use the Chrome extension Postman (now often referred to as Postman), you are simulating a standard browser interaction. However, if your web server is misconfigured, it might be stripping the body of the request or redirecting it before the PHP engine parses it. A common cause for this specific symptomâwhere GET works but POST failsâis that the application expects a file upload or has strict MIME type checking enabled via php.ini directives like upload_max_filesize or post_max_size. If the body content exceeds these limits, the server may reject the request silently or redirect it to an error handler.
Diagnosing the Server-Side Behavior
The fact that GET parameters work confirms your routing rules and PHP configuration are fundamentally sound for standard requests. The issue is isolated to how the server handles a POST body with application/x-www-form-urlencoded content.
Check your web server logs immediately. If you are using Apache, look for errors in the error log or mod_rewrite rules that might be interfering with POST requests. For example, if your .htaccess file contains a rule that rewrites all POST requests to a static file (like index.html), the PHP script will never execute because the request body is consumed by the static handler.
You should also verify that your PHP configuration allows for form data. Ensure that the following directives in your php.ini are set appropriately:
upload_max_filesize: Set to a value higher than your expected payload size (e.g., 10M).post_max_size: Must be greater than or equal toupload_max_filesize.
If these values are too low, the server will truncate the incoming data, leaving only the session cookie intact in the request context.
Checking for Middleware Interference
Another frequent culprit in modern frameworks is middleware that runs before the controller logic. If you have a global exception handler or an error response interceptor, it might be catching the request and returning an empty response or a default page. This often happens when the server thinks a POST request to a non-existent route should return a 404, but instead of a clean 404, it serves content that doesn't expose $_POST.
If you are using a framework like Laravel, ensure your routes are defined correctly and that no middleware is filtering out POST requests unexpectedly. You can debug this by adding a specific check in your controller to isolate the issue:
if (request()->is('post/*')) {
return response()->json(['method' => 'POST', 'content_type' => request()->header('Content-Type')]);
}
This snippet helps confirm if the framework is even acknowledging the POST method before your main logic runs.
The Role of Content-Type Headers
Ensure that Postman is sending the correct Content-Type header. While application/x-www-form-urlencoded is standard, some legacy servers or specific configurations might expect multipart/form-data for form submissions, especially if file uploads are involved. However, since you are dealing with simple parameters, the header is likely correct. The issue is almost certainly on the server side regarding how it parses the body.
If you have recently updated your web server or PHP version, check for compatibility issues. Some older PHP versions had stricter handling of $_POST depending on the magic quotes setting (though this is deprecated), but modern versions should handle this seamlessly unless misconfigured.
Final Verification Steps
Before concluding that there is a bug in Postman, remember that it is merely a client. The problem lies in the server's response or lack thereof. If you are hosting your own application, review your .htaccess or nginx.conf files for any rules that might be rewriting POST requests to static assets.
If you are using a third-party service or a specific hosting provider, their documentation often lists restrictions on POST body sizes or specific headers they block by default. Contacting their support with the request logs can quickly identify if the server is discarding the body due to security policies or misconfigured modules like mod_security in Apache.
By systematically checking your server logs, verifying PHP configuration limits, and ensuring no middleware is intercepting the request, you can resolve the discrepancy between GET and POST behavior without changing how you use Postman.
