Several ways for PHP to obtain post parameters
The data type recognized by PHP by default is application/x-www .form-urlencoded standard data type.
1. $_POST['paramName'] Only when the Content-Type is application/x-www-form-urlencoded or multipart/form-data, PHP will change the HTTP request packet The corresponding part of the body data is filled in the $_POST global variable, and PHP ignores other situations. The data filled into the $_POST array is the result of urldecode() parsing.
2. file_get_contents("php://input") is suitable for most types of Content-type
php://input allows reading the raw data of POST. It puts less pressure on memory than $HTTP_RAW_POST_DATA and does not require any special php.ini settings. php://input cannot be used with enctype="multipart/form-data".
3. $GLOBALS['HTTP_RAW_POST_DATA']; always generates $HTTP_RAW_POST_DATA variable containing the original POST data. This variable is only generated when data of an unrecognized MIME type is encountered. $HTTP_RAW_POST_DATA is not available for enctype="multipart/form-data" form data.
If the posted data is not recognized by PHP, you can use $GLOBALS['HTTP_RAW_POST_DATA'] to receive it, such as text/xml or soap, etc. You need to set the always_populate_raw_post_data value in php.ini to On so that PHP will always fill in the POST data into the variable $http_raw_post_data.
Look at the official documentation, in higher versions, this variable $HTTP_RAW_POST_DATA is deprecated
This feature wasDEPRECATEDin PHP 5.6.0, andREMOVEDas of PHP 7.0.0. In general,php://inputshould be used instead of $HTTP_RAW_POST_DATA.
Summary:
1, Coentent-Type is only used when the value is application/x-www-data-urlencoded and multipart/form-data. PHP will fill the corresponding data in the http request packet into the global variable $_POST
2. When PHP does not recognize the Content-Type type, it will fill in the corresponding data in the http request packet into the variable $. HTTP_RAW_POST_DATA
3, only when the Coentent-Type is not multipart/form-data, PHP will fill in the corresponding data in the http request packet into php: //input, otherwise it will be in other cases. The length of the padding, specified by Coentent-Length.
4. Only when the Content-Type is application/x-www-data-urlencoded, the php://input data is consistent with the $_POST data.
5, php://input data is always the same as $HTTP_RAW_POST_DATA. They only read data whose Content-Type is not multipart/form-data, but php://input is more efficient than $HTTP_RAW_POST_DATA. , and no special setting is required for php.ini
6. PHP will fill in the query_path part of the PATH field into the global variable $_GET. Normally, the body of an http request submitted by the GET method is empty.
7, php://input cannot read $_GET data. This is because the $_GET data is written in the PATH field of the http request header as query_path, rather than in the body part of the http request.
8. If it is application/x-www-form-urlencoded and multipart/form-data format, use $_POST;
9. If it cannot be obtained, such as text/xml, application /json, soap, use file_get_contents('php://input');
Recommended tutorial: "PHP Tutorial"
The above is the detailed content of Is there a way to get post parameters in php?. For more information, please follow other related articles on the PHP Chinese website!

The article compares ACID and BASE database models, detailing their characteristics and appropriate use cases. ACID prioritizes data integrity and consistency, suitable for financial and e-commerce applications, while BASE focuses on availability and

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

Article discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

The article discusses the benefits of using password_hash and password_verify in PHP for securing passwords. The main argument is that these functions enhance password protection through automatic salt generation, strong hashing algorithms, and secur

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

The article discusses strategies to prevent XSS attacks in PHP, focusing on input sanitization, output encoding, and using security-enhancing libraries and frameworks.

The article discusses the use of interfaces and abstract classes in PHP, focusing on when to use each. Interfaces define a contract without implementation, suitable for unrelated classes and multiple inheritance. Abstract classes provide common funct


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software