PHP GET and POST Method

In forms, information can be transferred and submitted to same or another page. We can submit the data through form. To submit the data through form, to helps GET and POST method to develope this operations.

A form data can be submitted using these two methods. Both are used for same purpose but stands apart under some specifications. As in GET method key values are passed in the Url while in POST, the information transfers in a hidden manner.





There are two ways the browser client can send information to the web server.

  1. GET Method
  2. The POST Method

First encodes the information using a scheme called URL encoding before the browser sends the information.

The GET Method

The GET method sends the encoded user information appended to the page request. The page and the encoded information are separated by the ? character.

Example Code




";
      echo "You are ". $_GET['user_age']. " years old.";
      
      exit();
   }
?>

   
   
      
Name: Age:

The POST Method

The POST method transfers information via HTTP headers. The information is encoded as described in case of GET method and put into a header called QUERY_STRING.

Example Code




";
      echo "You are ". $_REQUEST['user_age']. " years old.";
      exit();
   }
?>

   
      
      
Name: Age:

If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

Leave a Reply

Your email address will not be published.