In PHP, the predefined $_POST variable is used to collect values from the form with method="post".
The predefined $_POST variable is used to collect values from the form with method="post".
Information sent from a form with the POST method is invisible to anyone (it will not be displayed in the browser's address bar), and there is no limit on the amount of information sent.
Note: However, by default, the maximum amount of information sent by the POST method is 8 MB (can be changed by setting post_max_size in the php.ini file).
The form.html file code is as follows:
<html><head><meta charset="utf-8"><title>Coder Tutorial (codercto.com)</title></head><body><form action="welcome.php" method=" post">Name: <input type="text" name="fname">Age: <input type="text" name="age"><input type="submit" value="Submit"></form> </body></html>
When the user clicks the "Submit" button, the URL looks like this:
http://www.codercto.com/welcome.php
The "welcome.php" file can now collect form data via the $_POST variable (note that the form field names automatically become keys in the $_POST array):
Welcome<?php echo $_POST["fname"]; ?>!<br>Your age is <?php echo $_POST["age"]; ?> years old.
Information sent from a form with the POST method is not visible to anyone, and there is no limit on the amount of information sent.
However, since the variable does not appear in the URL, the page cannot be bookmarked.
The predefined $_REQUEST variable contains the contents of $_GET, $_POST and $_COOKIE.
The $_REQUEST variable can be used to collect form data sent via GET and POST methods.
You can modify the "welcome.php" file to the following code, which can accept $_GET, $_POST and other data.
Welcome<?php echo $_REQUEST["fname"]; ?>!<br>Your age is <?php echo $_REQUEST["age"]; ?> years old.