Share on Google+Share on Google+

The $_GET Function

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" />

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">
<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"/>

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

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


Posted on: February 4, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.