例子:用getenv函数获取各种CGI环境变量
类别: PHP教程
<?
$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>';
?>
$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>';
?>
- 上一篇: 例子:计算两个时间相差的天数
- 下一篇: 例子:把字符串时间转换为timestamp
-= 资 源 教 程 =-
文 章 搜 索