Parameters are passed in the URL

Parameters are passed in a URL by separating it with a ? and then passing them as an id/value pair separated by &. For example:

http://www.lthash.com/6-php/get.php?name=pthakran&password=123456&language=en

GET'ing the paramaters

Parameters that are passed onto a PHP page are stored in a array called $_GET where the index is the name of the parameter, and the value is the parameter value that was passed.

Any array opearions can be performed on $_GET as we have seen before. For example:

echo "Here is the content of the parameters that were passed to this PHP page:<br><br>";
print_r($_GET)."<br><br>";

echo "Here is the content of each parameter:<br><br>";

foreach ($_GET as $keyGet => $valueGet){
echo "Parameter "".$keyGet."" has a value of "".$valueGet."".<br>";
}


Here is the content of the parameters that were passed to this PHP page:

Array ( ) Here is the content of each parameter:

How to pass parameters in the URL

Parameters can be passed by hardcoding the link which is clicked on. Alternatively, you can capture the paramers by a form.
When using a form the parameters are passed in the URL when the form is submitted. Here is an example:

Creating Interaction

In the following example we're going to ask the user to enter a number, and then respond back with whether it is a prime number or not using PHP: