Home >Backend Development >PHP Tutorial >php $_get[] usage_PHP tutorial
php教程中$_get要获取表单的数据那必须把METHOD=GET才行,否则就无法正常获取值哦,
$_GET 变量是一个数组,内容是由 HTTP GET 方法发送的变量名称和值。
$_GET 变量用于收集来自 method="get" 的表单中的值。从带有 GET 方法的表单发送的信息,对任何人都是可见的(会显示在浏览器的地址栏),并且对发送的信息量也有限制(最多 100 个字符)。
看个获取表单数据的实例
//Properly determining which submission button was clicked in PHP:if(isset($_GET['submit_one_x'])) {
} elseif(isset($_GET['submit_two_x'])) {
} else {}
?>
实例二
if($_GET['time']+300 >= time()) {
echo "You took too long!
";
exit;
}
?>
操作select值
//The PHP code to access which value(s) were selected:foreach($_GET['myselect'] as $val) {
echo "You selected: $val
";
}
echo "You selected ".count($_GET['myselect'])." Values.";
?>
获取表单提交的数据再输出,这也是个完整的实例
A Simple HTML Form
// index.php
print "Welcome " . $_GET ['user'] . "
nn";
print "Your address is:
" . $_GET ['address'] . "";
?>
Note: 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.
Note: The HTTP GET method is not suitable for large variable values; values cannot exceed 100 characters