Tuesday, October 27, 2015

PHP GET & POST METHODS | phpeasylearning.tk

There are two methods to send information from clients (Browser) to Web Server:
  • GET METHOD
  • POST METHOD

GET METHOD

In GET method the form data can be requested to collect information after submit button clicked form with method=”GET”.

The example below shows a HTML form with two input field and button to send the information to “get_welcome.php

<html>
<body>
<formaction="get_welcome.php"method ="GET">
     Full Name: <inputtype="text"name="fname"/><br/>
     Username : <inputtype="text"name="uname"/><br/>
<inputtype="Submit"/>
</form>
</body>
</html>

get_welcome.php

<html>
<body>
<?php
if($_GET["fname"]||$_GET["uname"])
{
echo"Welcome ".$_GET['fname']."<br />";
echo"Your Username is “.$_GET['uname'];
exit();
}
?>
</body>
</html>

For output copy above codes and run the script.
In the example above when user fill the form and click submit button, the data is sent to PHP file named “get_welcome.php” for processing. The method used in that form is “GET” which is used to send form data.
In GET method When the submit button clicked the information (name/value pairs) appeared in the URL and are visible to everyone

/PHP_Examples/get_welcome.php?fname=namevalue&uname=unamevalue

The question marks“?”character separates the page and form information or variables and information (name/ values) are separated by ampersand “&”character as you can see in above URL.

HTTP POST Method

In POST method the form data can be requested to collect information after submit button clicked form with method =”POST”. This method is used widely. The information sent to server using HTTP request.
We can take same above “GET Method” example for POST Method


continue reading...