欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

例子:用getenv函数获取各种CGI环境变量

程序员文章站 2022-04-02 17:52:49
...

cgi|变量|函数


$array = array(
"REMOTE_ADDR",
"DOCUMENT_ROOT",
"GATEWAY_INTERFACE",
"SERVER_SOFTWARE",
"SERVER_NAME",
"SERVER_PROTOCOL",
"SERVER_PORT",
"SERVER_ADMIN",
"SERVER_SIGNATURE",
"REQUEST_METHOD",
"REQUEST_URI",
"PATH_INFO",
"PATH_TRANSLATED",
"SCRIPT_NAME",
"SCRIPT_FILENAME",
"QUERY_STRING",
"REMOTE_HOST",
"REMOTE_ADDR",
"REMOTE_USER",
"REMOTE_IDENT",
"CONTENT_TYPE",
"CONTENT_LENGTH",
"HTTP_ACCEPT",
"HTTP_ACCEPT_CHARSET",
"HTTP_ACCEPT_LANGUAGE",
"HTTP_ENCODING",
"HTTP_USER_AGENT",
"HTTP_CONNECTION",
"HTTP_HOST",
"HTTP_REFERER",
"AUTH_TYPE"
);

echo '

';
echo '';
echo '';
echo '';

$count = count($array);
for($i=0;$i $value = getenv($array[$i]);
if($value){
echo "";
}
//下面的语句也可以哦
// if(isset($$array[$i])){
// echo "";
// }
}

echo '
CGI Environment Variables
Name Value
$array[$i] " . $value . "
$array[$i] " . $$array[$i] . "
';
echo '
';
?>