$_GET

$_GETHTTP GET 变量

说明

通过 URL 参数(又叫 query string)传递给当前脚本的变量的数组。 注意:该数组不仅仅对 method 为 GET 的请求生效,而是会针对所有带 query string 的请求。

示例

示例 #1 $_GET 范例

<?php
echo 'Hello ' . htmlspecialchars($_GET["name"]) . '!';
?>

假设用户访问的是 http://example.com/?name=Hannes

以上示例的输出类似于:

Hello Hannes!

注释

注意:

“Superglobal”也称为自动化的全局变量。这就表示其在脚本的所有作用域中都是可用的。不需要在函数或方法中用 global $variable; 来访问它。

注意:

GET 是通过 urldecode() 传递的。

add a note add a note

User Contributed Notes 1 note

up
-1
An Anonymous User
2 years ago
<?php
// It is important to sanitize
// input! Otherwise, a bad actor
// could enter '<script src="evilscript.js"></script>'
// in a URL parameter. Assuming you echo it, this
// would inject scripts in an XSS attack.
//
// The solution:
$NAME = $_GET['NAME'];
// Bad:
echo $NAME;
// that one is vulnerable to XSS
// Good:
echo htmlspecialchars($NAME);
// Sanitizes input thoroughly.
?>
To Top