Home > Article > Backend Development > How to Access Request Payload in PHP When $_POST and $_GET Are Empty?
When using ExtJS and ajax store, request data may be sent in the HTTP request body instead of through POST or GET parameters. Consequently, $_POST and $_GET remain empty.
The request body can be accessed using the following PHP code:
$request_body = file_get_contents('php://input');
If the payload is in JSON format, it can be decoded with:
$data = json_decode($request_body);
This will populate the $data variable with an array representing the JSON payload.
php://input is a read-only stream wrapper that provides access to raw data from the request body. It is particularly useful for POST requests and offers advantages over $HTTP_RAW_POST_DATA in terms of memory efficiency and independence from specific php.ini directives. Note that php://input is not available when using enctype="multipart/form-data".
The above is the detailed content of How to Access Request Payload in PHP When $_POST and $_GET Are Empty?. For more information, please follow other related articles on the PHP Chinese website!