Rumah >php教程 >php手册 >例子:用getenv函数获取各种CGI环境变量

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

WBOY
WBOYasal
2016-06-21 09:13:331285semak imbas

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 '
';
?>



Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn