To make the website work effectively, a lot of HTTP requests are sent using the HTML form from the browser to the server. While PHP is a processor module of web servers, it helps to process these form data effectively. Once PHP intercepts the data sent via HTML and uses POST method to send them, $_POST is an array that plays the role of holding all the information. This tutorial is going to help you, beginners in particular, have a better understanding about $_POST and start a wonderful PHP journey.
What is PHP $_POST
In a word, the $_POST is an associative array of variables sent to the current script via HTTP POST method. This $_POST variable is created to collect all the information from the method = “post”. There is no need to worry about your private information going public because all the form data sent by POST method are invisible. Need to send a large amount of information? No problem. There is no restriction on the size of the data to be sent.
Note：By default, however, the maximum value is 8 MB when using POST method to send information and the value can be reset by setting up post_max_size in the php.ini files.
We have displayed an example in the following to help you better understand PHP $_POST.
When click the “submit” button, the URL would be:
Note that the parameter of “welcome” can be changed according to the
Thus the PHP code excerpted from “welcome.php” would be:
Note: the form names would become the ID keys in $_POST array automatically.
$_POST is 1 of the 3 arrays contained in $_REQUEST array, and the other 2 are $_GET and $_Cookie. In this case, PHP $_REQUEST variable can be used to get the contents in $_POST as well as the other 2 arrays.
Here is an example:
When Use It?
From the description above, it can be learned that no form data is visible in URL with PHP $_POST. As a result, for safety consideration, it is suitable to send sensitive form data using POST method. For instance, when registering and logging into the account, the password does not have the opportunity to be released.
Moreover, since there is no limitation on the number of bytes, you can send as much information as you desire. It means that you can never worry about the possibility of failing to submit an essay just because of the excess of the bytes. If there is any chance that you need to upload some files with the form data, POST method is the right choice.
On the other hand, the absence of form data from URL also causes some inconvenience. For example, you are unable to add the page that you frequently visit to the bookmark. In the case of reading news on the Internet using POST method, it is incapable to recognize the corresponding URL since the form data is invisible, which makes it pretty difficult to share interesting news.