php中超全局变量是一类预定义的全局变量数组,可在脚本中使用,无需开发者声明即可访问,这些数组包括$_get,$_post,$_request,$_cookie等。
本教程操作系统:windows10系统、php8.1.3版本、dell g3电脑。
php超级全局变量数组(super global array),又称为php预定义数组,是由php引擎内置的,不需要开发者重新定义。 在php脚本运行时,php会自动将一些数据放在超级全局数组中。
1、$_get 数组用于收集通过 get 方法提交的表单数据,通常以 url 参数形式出现
<form action="process.php" method="get"> name: <input type="text" name="name"><br> age: <input type="text" name="age"><br> <input type="submit"></form>// process.php$name = $_get['name'];$age = $_get['age'];echo "welcome $name! you are $age years old.";
2、$_post 数组用于收集通过 post 方法提交的表单数据,可用于处理敏感数据
<form action="process.php" method="post"> name: <input type="text" name="name"><br> age: <input type="text" name="age"><br> <input type="submit"></form>// process.php$name = $_post['name'];$age = $_post['age'];echo "welcome $name! you are $age years old.";
3、$_request 数组包含了get、_post、$_cookie 的内容。可以用来收集 html 表单提交后的数据或者从浏览器地址栏中获取数据。
<form action="process.php" method="post"> name: <input type="text" name="name"><br> age: <input type="text" name="age"><br> <input type="submit"></form>// process.php$name = $_request['name'];$age = $_request['age'];echo "welcome $name! you are $age years old.";
4、$_cookie 数组用于访问已在客户端计算机上存储的 cookie
// send_cookie.phpsetcookie('username', 'john', time() + (86400 * 30), "/"); // 设置 cookieecho 'cookie sent.
以上就是什么是php超全局变量数组的详细内容。