什么是php超全局变量数组

PHP中超全局变量是一类预定义的全局变量数组,可在脚本中使用,无需开发者声明即可访问,这些数组包括$_GET,$_POST,$_REQUEST,$_COOKIE等。

本教程操作系统:Windows10系统、php8.1.3版本、Dell G3电脑。

PHP超级全局变量数组(Super Global Array),又称为PHP预定义数组,是由PHP引擎内置的,不需要开发者重新定义。 在PHP脚本运行时,PHP会自动将一些数据放在超级全局数组中。

1、$_GET 数组用于收集通过 GET 方法提交的表单数据,通常以 URL 参数形式出现

1

2

3

4

5

6

7

8

9

<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 方法提交的表单数据,可用于处理敏感数据

1

2

3

4

5

6

7

8

9

<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 表单提交后的数据或者从浏览器地址栏中获取数据。

1

2

3

4

5

6

7

8

9

<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

1

2

3

// send_cookie.php

setcookie(username, John, time() + (86400 * 30), “/”); // 设置 cookie

echo Cookie sent.

登录后复制

以上就是什么是php超全局变量数组的详细内容,更多请关注php中文网其它相关文章!

TG交流群(点击进入)----付费帮助搭建---修复---二开,以及发布求资源.
QQ交流群 922260178
© 版权声明
THE END
喜欢就支持一下吧
点赞6596 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容