How to Use GET Method in php


There are three types of form methods GET,POST and REQUEST. Get method is not used more because it has a drawback. When the form is submit then all the fields data are displayed in url with the variable name and its value , hence every one can see the fields and it can be risky. There cant be any Privacy. Url has 255 length to hold the string so some time big string can create problems. We need to set form type as GET so the get method will be applicable when the form is submitted.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Example for Using GET Method in PHP</title>
<!--We will create one simple form with two fields first name and last name-->
<!--This is the simple example for get method with form in php-->
<!-- We need to set method="get" for the Get Method-->
<form name="myform" action="" method="get" id="myform">
<label>First Name</label>
<input type="text" name="fname" id="fname" value="" />

<label>Last Name</label>
<input type="text" name="lname" id="lname" value="" />
<input type="submit" value="Submit" name="save" id="save" />

echo 'Your Name-'.$_GET['fname'].' '.$_GET['lname'];