Introduction
$_GET is an associative array of variables passed to the current script via query string appended to URL of HTTP request. Note that the array is populated by all requests with a query string in addition to GET requests.
$HTTP_GET_VARS contains the same initial information, but has been deprecated
By default, client browser sends a request for URL on the server by HTTP GET method. A query string attached to URL may contain key=value pairs concatenated by & symbol. The $_GET associative array stores these key value pairs
Assuming that the URL in browser is https://localhost/testscript.php?name=xyz&age=20
Example
<?php echo "Name : " . $_GET["name"] . "<br>"; echo "Age : " . $_GET["age"]; ?>
Output
This will produce following result −
Name : xyz Age : 20
In following example, htmlspecialchars() function is used to convert characters in HTML entities.
Character | Replacement |
---|---|
< (less than) | < |
' (single quote) | ' or ' |
" (double quote) | " |
& (ampersand) | & |
> (greater than) | > |
Assuming that the URL in browser is https://localhost/testscript.php?name=xyz&age=20
Example
<?php echo "Name: " . htmlspecialchars($_GET["name"]) . "<br>"; echo "age: " . htmlspecialchars($_GET["age"]) . "<br>"; ?>
Output
This will produce following result −
Name : xyz Age : 20