The $_GET Function


 

The $_GET Function

This section contains the detail about the $_GET Function in php.

This section contains the detail about the $_GET Function in php.

The $_GET Function

The $_GET function in PHP is used to gather data of form submit with method="get". The data sent using get method is visible in browser's address bar.

For sending username & password , get  method is not secure. It also has limits on the amount of information to send. Given below form uses get method for sending data :

<form action="registration.php" method="get">
Name : <input type="text" name="name" />
Address : <input type="text" name="address" />
<input type="submit" />
</form>

Fetching form data sent via GET method

You can fetch value of submitted form in a PHP page using $_GET method as follows :

Your Name :<?php echo $_GET["name"]; ?>.<br />
Address :<?php echo $_GET["address"]; ?>

The above lines display the name & address values of submitted form.

The Given below the complete example, which will give you a clear idea :

Example :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>GET Method in PHP</TITLE>
</HEAD>
<BODY>
<h3>Fill the Below Form :</h3>
<form action="registration.php" method="get">
Name: <input type="text" name="name" /><br>
Address : <input type="text" name="address" /><br/>
<input type="submit" name="submit"/>
</form>
</BODY>
</HTML>

<?php
if(isset($_GET['submit'])){
?>
Your Name :<?php echo $_GET["name"]; ?>.<br />
Address :<?php echo $_GET["address"]; ?>
<?php
}
?>

Output :

First, you need to fill up the form as :

When you press the submit button, it will show you the following :(Also, See the browser address bar)

Download Source Code

Ads