gpt4 book ai didi

php - $_SERVER 和 $_ENV 之间的区别

转载 作者:可可西里 更新时间:2023-11-01 12:57:35 51 4
gpt4 key购买 nike

我对超全局数组 $_ENV 和 $_SERVER 的理解是否正确?

$_ENV: Contains information about environment variables
$_SERVER: Contains information about the server

$_ENV is accessible from both web server and on the command line
$_SERVER is accessible through only web server, not on the command line

最佳答案

将这段代码放在一个文件中:

<?php
header('Content-Type: text/plain');

echo('$_ENV[] = '); print_r($_ENV);
echo('$_SERVER[] = '); print_r($_SERVER);

使用命令行和网络服务器运行它,看看会得到什么。

令我惊讶的是,在我的计算机上,$_ENV[] 在两个设置中都是空的,并且当代码从 CLI 运行时,$_SERVER[] 包含环境变量。

一般来说,结果在很大程度上取决于您使用的操作系统和网络服务器。

关于php - $_SERVER 和 $_ENV 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32901233/

51 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com