Pass information using POST method

Passing variables using URL method having several disadvantages such as :
(1) It is insecure because information is visible in the URL.
(2) It allows you to transfer limited amount of information.
Most programmers avoid the use of that method.
PHP provides alternative solution by allowing passing information through FORM body instead of passing it through URL. You can pass information between pages using POST method of the FORM that allows you to transfer information through FORM body.
When you are using POST method to transfer information between pages it will transfer information through FORM body. It offers following advantages to the user:
(1) Hence information is transferred through FORM body it is not visible to everyone. Thus it is secure method.
(2) Hence information is transferred through FORM body it allows you to transfer larger amount of data.
Step 1: Create FormBody1.Php file as shown below:


<title>Passing Information Using Form Body</title>
<form name="Form1" method="POST" action="FormBody2.php">
Enter Your Name:<br>
<input type="Text" name="Name" ><br>
Enter Your City:<br>
<input type="Text" name="City" ><br>
<input type="submit" name="submit" value="Submit">

Step 2: Create FormBody2.php file as shown below:

$Name = $_POST['Name'];
$City = $_POST['City'];
echo "Your Name is ".$Name. "<br/>";
echo "You Live In ".$City. "<br/>";

In above script we use $_POST [‘Variable Name’] function which allows you to retrieve value of the variables through FORM collection.
Step 3: Now run the FormBody1.php file
Using Form

After entering Name and City in the textbox when you click on submit button, it will transfer name and city through FORM collection as shown below:

Using Form
You can also use $_REQUEST [‘VariableName’] instead of $_POST [‘VariableName’] in the above code to retrieve value from FORM collection.

Download Projects

Download Programs