08 Jul PHP POST Method
For sending information to the web server, which is secure, use the PHP POST method. The information sent through the server isn’t visible in the URL, unlike the PHP GET() method.
Let’s learn about some interesting points about the POST method,
- Use POST, if you want to send passwords.
- Information sent via the GET method is hidden and can’t be seen in the URL.
- There is no limitation on characters while sending information through POST.
- PHP superglobals $_POST is used to collect form data with POST.
- You can send ASCII as well as binary data, via GET.
Example
Here, we have two files. The first one is an HTML form,
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<html> <body> <form action="success.php" method="post"> Name: <input type="text" name="name"><br> Age: <input type="number" name="age"><br> <input type="submit"> </form> </body> </html> |
The second file is success.php which will open if the form submission is successful. We’re using superglobal variable $_POST to collect form data with POST.
1 2 3 4 5 6 7 8 9 10 |
<html> <body> Hi, User: <?php echo $_POST["name"]; ?><br> Your age: <?php echo $_POST["age"]; ?> </body> </html> |
Here, you can see the variable values name and age aren’t visible in the address bar. One of the benefits of using the POST method is that it is secure since the values are hidden.
No Comments