Trending September 2023 # Examples And Uses Of Function $_Post # Suggested October 2023 # Top 12 Popular |

Trending September 2023 # Examples And Uses Of Function $_Post # Suggested October 2023 # Top 12 Popular

You are reading the article Examples And Uses Of Function $_Post updated in September 2023 on the website We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested October 2023 Examples And Uses Of Function $_Post

Introduction to PHP $_POST

PHP comes out a function of $_POST that is a super global variable that is used to collect the data. After submitting an HTML Form some data is generated which is collected using a specific method POST. $_POST is also used for passing variables. It is basically passed to the HTTP POST method as the content type in the request. This is a super variable/automatic global variable whose scope is available throughout the script that means there is no need to declare a global variable to access this. This method _POST is available after the stable release of PHP 4 and above.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others


<?php $_POST['name'] "$_POST[…]" is the PHP array 'name'" is the URL variable name.

Screenshot :

$_POST Variable Working

The $_POST variable collects the data from the HTML form via the POST method. When a user fills the data in a PHP form and submits the data that is sent can be collected with the _POST Method in PHP. The Post Method transfers the information via the Headers. The Information is encoded using a scheme where the KEY/VALUE pairs are joined with an equal sign. All the special characters are removed and the data is encoded. Once we get the encoded data it is sent to a header called QUERY_STRING.

It doesn’t have the limit of data size to be sent in this QUERY_STRING. Both Binary, as well as ASCII data, can be sent of with the POST method. The data is then passed with some security protocol making the information secured and then sent to an associative array using the $_POST method.

The data sent by the POST Method is invisible to others and we cannot see any form of data when passed on. _POST is an array of variable passed to script via the HTTP Post Method.

The time spent by method POST is more than that of the other request that is why it has some what low performance, But it is widely used as the exposure for this is more as it supports many data types such as String, numeric, binary. And since the Values are not visible the result cannot be book marked.

The Post method is used for creating complex Form in HTML and to handle complex data are sent over the network.

So after the URL is Hit the URL will be something like that with the POST Method:

Localhost/pagename.php Examples of PHP $_POST

Let us see some functioning of $_POST with some Example:

Example #1

Let’s start by creating an HTML form and see how the Request Generates.

Method Used Post:


This is HTML form.

PHP POST Request Method:

<?php if ($_SERVER["REQUEST_METHOD"] == "POST") { $name = htmlspecialchars($_REQUEST['sname']); if (empty($name)) { echo "Empty Name"; } else { echo $name; } }

Here the htmlspecialchars($Request[‘fname’]) takes the value of Input Field and checks whether any condition is given over there or not. If any condition is there that is checked or else the data is collected. So the Output for this will be something like:


Let us check some more example:

Let’s create a Form that takes data from two field Name and Email of a user and let’s collect that using the POST Method. We will create a PHP File called Demo.php

Here is the Code:

Create an HTML form with the Request with POST.



When we request or run this PHP code the request is generated and data is sent for processing.

Example #2

Let us check one more simple Example:

Simple POST Request to get the Address and City



We can use the isset function to check whether the value for this variable has been set or not. We can use conditional statements also with this method.




From the above article, we saw the use of Function $_POST in PHP. From various example and classification we tried to understand how the $_POST function works in PHP and what are is use in the programming level.

Recommended Articles

This is a guide to PHP $_POST. Here we discuss the introduction to PHP $_POST, How PHP $_POST works in PHP, and Examples with code implementation?. You can also go through our other suggested articles to learn more –

You're reading Examples And Uses Of Function $_Post

Update the detailed information about Examples And Uses Of Function $_Post on the website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!