PHP Get and Post

Get & post in Php

PHP Get Form

PHP Get and Post : Information sent via a form using the GET method is visible to everyone (all variable names and values are displayed in the URL). GET also sets limits on the amount of information that can be sent – about 2000 characters.

However, because the variables are displayed in the URL, it is possible to bookmark the page, which can be useful in some situations.


Let’s see a simple example to receive data from get request in PHP.

File: form1.html

<form action="welcome.php" method="get">

Name: <input type="text" name="name"/>

<input type="submit" value="visit"/>

</form>

File: welcome.php

<?php

$name=$_GET["name"];//receiving name field value in $name variable

echo "Welcome, $name";

?>

PHP Post Form

Information sent from a form via the POST method is invisible to others, since all names and/or values are embedded within the body of the HTTP request. Also, there are no limits on the amount of information to be sent.

Moreover, POST supports advanced functionality such as support for multi-part binary input while uploading files to the server.

However, it is not possible to bookmark the page, as the submitted values are not visible.


Let’s see a simple example to receive data from post request in PHP.

File: form1.html

<form action="login.php" method="post"> 

<table> 

<tr><td>Name:</td><td> <input type="text" name="name"/></td></tr>

<tr><td>Password:</td><td> <input type="password" name="password"/></td></tr> 

<tr><td colspan="2"><input type="submit" value="login"/>  </td></tr>

</table>

</form> 

File: login.php

<?php

$name=$_POST["name"];//receiving name field value in $name variable

$password=$_POST["password"];//receiving password field value in $password variable



echo "Welcome: $name, your password is: $password";

?>

Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *