Loading

PHP Global Variable $_GET

PHP $_GET is a super global or automatic global variable. It uses to collect form data after submitting a form with the “get” method. It passes data in an associative array. Form “get” method passes an associative array of data via URL and PHP $_GET method collects those data.

So, $_GET can collect data that come via URL.

So, $_GET can populate all URL query strings (aka, URL parameter).

Some important points:-

  1. The GET method is restricted to sending up to 1024 characters only.
  2. We cannot pass any sensitive data like:- user name, password, etc. using the GET method.
  3. We cannot pass any binary data like images, pdf, word documents, etc. using the GET method.
  4. GET method can be useful in pagination, AJAX calls, etc.

Example:-

http://kshtutor.com/?name=ksh

$name = $_GET[‘name’];

echo $name;

//output:- ksh

HTML Form Example:-

<?php

if( $_GET[“animal”] || $_GET[“type”] ) {

echo “Your “. $_GET[animal]. “<br />”;

echo “Animal Type  “. $_GET[type];

exit();

}

?>

<html>

<body>

<form action = “<?php $_PHP_SELF ?>” method = “GET”>

Animal :  <input type = “text” name = “animal” />

Type :  <input type = “text” name = “type” />

<input type = “submit” />

</form>

Read Also:-

PHP VARIABLES

PHP Global Variable $_SERVER

PHP $GLOBALS Variable

PHP predefined variables

How to code a PHP application

For more detail about variables please see manual

Leave a Reply

z35W7z4v9z8w
Verified by ExactMetrics