Introduction to $_ GET Array in PHP

  • 2021-11-29 23:24:44
  • OfStack

GET and POST are ubiquitous in the development process. The $_GET variable is an array of variable names and values sent by the HTTP GET method.

The $_GET variable is used to collect values from the form where method= "get". The information sent from the form with the GET method is visible to anyone (displayed in the browser's address bar), and there is a limit to the amount of information sent (up to 100 characters).

When using the $_GET variable, all variable names and values are displayed in URL. Therefore, this method should not be used when sending passwords or other sensitive information. However, because the variable is displayed in URL, you can keep the page in Favorites. In some cases, this is very useful.

1 Generally speaking, URL will use & Operator to separate multiple variables, of course, you can also set it to other symbols. Using the symbol ',' as the variable separator, we can do this in two ways:

1. Modification of php. ini


 -- 
; list of separator(s) used by php to parse input urls into variables.
; default is "&". 
; note: every character in this directive is considered as separator!
arg_separator.input = ";,"
 -- 

2. Write your own explanatory grammar


list($key,$value)=$_get;  // Will get Decompose variables 
$tmp=explode(",",$value);  // Separate the data 

The advantage of this usage is that others can't know who uses the values you pass, and you need to understand the use of each value yourself.

For http://www.codetc.com/test.php? website=codetc, which is the first class of get method, is actually the same as method 2. What is needed is to convert key into value for decomposition. I think this method is better and more convenient than the previous method.


$value = key($_GET);
$tmp = explode(",", $value);
print_r($tmp);

You should have already obtained these data.

To traverse the $_GET variable with multiple elements, you can use the following method:


while( list($key, $value) = each($_GET) )
{
 echo "Key: $key; Value: $value <br />";
}

You can also use:


foreach ($_GET as $key => $value) {
 echo "Key: $key; Value: $value <br />n";
}

Regarding the $_REQUEST variable, the $_REQUEST variable of PHP contains the contents of $_GET, $_POST, and $_COOKIE. The $_REQUEST variable of PHP can be used to obtain the results of the form data sent through the GET and POST methods.

Summarize


Related articles: