首页 > 开发 > PHP > 正文

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

2024-05-04 22:54:59
字体:
来源:转载
供稿:网友
<?
$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 '<center>';
echo '<table border="1" cellspacing="0" cellpadding="0">';
echo '<caption>cgi environment variables</caption>';
echo '<tr><th>name<th>value</tr>';

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

echo '</table>';
echo '</center>';
?>


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表