Pages

PHP $_GET

The PHP $_GET function is used to transfer information from page to page.Basically the PHP $_GET function retrieves variables embedded in the url after the ? sign.If more than two,these variables are separated with & sign.
If you are familiar with ASP.Net you will find PHP $_GET function as a replacement of Querystring.To get data with PHP $_GET is not a secure way of sending data from one page to another because all the information is visible in the url, but for simple use it is very handy.

The PHP $_GET function may be utilized in two different methods.The first method is just redirecting the user to a url of this format www.url.com/phpscript.php?variable=data in this case the data will be retrieved with $_GET["variable"];.The other method is an HTML form with its method="get" property,in this case when the form is submitted it automatically insert all the data of its elements i.e text,checkbox,radio button in the url of its action script.For illustration check out this example.

<html>

<head>

<title>PHP $_GET demo</title>

</head>

<body>

<h2><i>Who are you?</i></h2>

<form method="get" action="Form1script.php">

<p>Name: <input type="text" name="_name" size=10></p>

<p>Nick: <input type="text" name="_nick" size=10></p>

<p><input type="submit" value="Enter"></p>
</form>
</body>
</html>
The text shown above is the HTML form with two text boxes which are used to take input from user.Have a look at the name attribute of the text fields this is the name which will be retrieved by the $_GET function
<?php

$name = $_GET["_name"];

$nick = $_GET["_nick"];

echo 'Hello '.$name;

echo 'Your nick is '.$nick;

?>
The PHP script shown above will retrieve all the data sent by the form with its $_GET function.

 

0 comments:

Post a Comment