Home > Backend Development > PHP Tutorial > Talk about $_GET array in PHP_PHP tutorial

Talk about $_GET array in PHP_PHP tutorial

WBOY
Release: 2016-07-13 10:33:22
Original
980 people have browsed it

During the development process, GET and POST are like souls, everywhere. The $_GET variable is an array containing the variable names and values ​​sent by the HTTP GET method.

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

When using $_GET variables, all variable names and values ​​will be displayed in the URL. So this method should not be used when sending passwords or other sensitive information. However, because the variables appear in the URL, you can bookmark the page. In some cases this is useful.

Generally speaking, URLs will use the & operator to separate multiple variables. Of course, you can also set it to other symbols. Use the ',' symbol as the variable separator symbol. Here we can use two methods to achieve it:

1. Modify 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 = ";,"
————
Copy after login

2. Write your own explanation grammar

list($key,$value)=$_get;    //将get变量分解出来
$tmp=explode(",",$value);    //将数据分出
Copy after login

The advantage of this usage is that others cannot know who uses the value you pass, and you need to understand the use of each value.

For the value passing of get methods such as http://www.bkjia.com/test.php?website=bkjia.com, the method is actually the same as method two. What is needed is to convert the key into value for decomposition. , I think this method is better than the previous method and more convenient.

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

You should have 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 />";
}
Copy after login

Also available:

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

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/752502.htmlTechArticleIn the development process, GET and POST are like souls, everywhere. The $_GET variable is an array containing the variable names and values ​​sent by the HTTP GET method. The $_GET variable is used to collect data from...
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template