$_SERVER 相关

$_SERVER

$_SERVER是一个服务器端的变量数组,提供许多关于服务器及客户端请求的变量值,象客户端浏览器类型、IP地址等
通过 print_r($_SERVER)
可以输出其中包含了那些内容

以下是通过指定参数输出对应的信息

/phpTest.php?id=2222&name=name1

标注不完整。
//全部的http信息
echo('1 . ALL_HTTP='.$_SERVER['ALL_HTTP']);

//如果通过https访问,则被设为一个非空的值(on),否则返回off     
echo('2 . HTTPS='.$_SERVER['HTTPS']);  

//#包含当前脚本的路径。这在页面需要指向自己时非常有用。          
echo('3 . SCRIPT_NAME='.$_SERVER['SCRIPT_NAME']);

//COOKIE
echo('4 . HTTP_COOKIE='.$_SERVER['HTTP_COOKIE']);

//#当 PHP 运行在 Apache 模块方式下
echo('5 . AUTH_PASSWORD='.$_SERVER['AUTH_PASSWORD']);

//#当 PHP 运行在 Apache 模块方式下,并且正在使用 HTTP 认证功能,这个变量便是认证的类型       
echo('6 . AUTH_TYPE='.$_SERVER['AUTH_TYPE']);

//#当 PHP 运行在 Apache 模块方式下    
echo('7 . AUTH_USER='.$_SERVER['AUTH_USER']);

           
echo('8 . CONTENT_LENGTH='.$_SERVER['CONTENT_LENGTH']);

    
echo('9 . CONTENT_TYPE='.$_SERVER['CONTENT_TYPE']);   

//#当前脚本所在文件系统(不是文档根目录)的基本路径。
echo('10. PATH_TRANSLATED='.$_SERVER['PATH_TRANSLATED']);

//查询(query)的字符串。
echo('11. QUERY_STRING='.$_SERVER['QUERY_STRING']);

//当前用户 IP 。   
echo('12. REMOTE_ADDR='.$_SERVER['REMOTE_ADDR']);

//当前用户主机名   
echo('13. REMOTE_HOST='.$_SERVER['REMOTE_HOST']);

          
echo('14. REMOTE_USER='.$_SERVER['REMOTE_USER']);

//访问页面时的请求方法
echo('15. REQUEST_METHOD='.$_SERVER['REQUEST_METHOD']);

//服务器主机的名称。
echo('16. SERVER_NAME='.$_SERVER['SERVER_NAME']);

//端口
echo('17. SERVER_PORT='.$_SERVER['SERVER_PORT']);

//请求页面时通信协议的名称和版本
echo('18. SERVER_PROTOCOL='.$_SERVER['SERVER_PROTOCOL']);

//服务器标识的字串
echo('19. SERVER_SOFTWARE='.$_SERVER['SERVER_SOFTWARE']);

    
echo('20. APPL_MD_PATH='.$_SERVER['APPL_MD_PATH']);


echo('21. APPL_PHYSICAL_PATH='.$_SERVER['APPL_PHYSICAL_PATH']);


echo('22. INSTANCE_ID='.$_SERVER['INSTANCE_ID']);

       
echo('23. INSTANCE_META_PATH='.$_SERVER['INSTANCE_META_PATH']);   
echo('24. LOGON_USER='.$_SERVER['LOGON_USER']);

//URL        
echo('25. REQUEST_URI='.$_SERVER['REQUEST_URI']);

      
echo('26. URL='.$_SERVER['URL']);    

//#当前执行脚本的绝对路径名。   
echo('27. SCRIPT_FILENAME='.$_SERVER['SCRIPT_FILENAME']); 

echo('28. ORIG_PATH_INFO='.$_SERVER['ORIG_PATH_INFO']);
   
echo('29. PATH_INFO='.$_SERVER['PATH_INFO']);
       
echo('30. ORIG_PATH_TRANSLATED='.$_SERVER['ORIG_PATH_TRANSLATED']);

//当前运行脚本所在的文档根目录
echo('31. DOCUMENT_ROOT='.$_SERVER['DOCUMENT_ROOT']);

//正在执行脚本的文件名
echo('32. PHP_SELF='.$_SERVER['PHP_SELF']);

当前请求的 Connection: 头部的内容。例如:“Keep-Alive”。              
echo('33. HTTP_CONNECTION='.$_SERVER['HTTP_CONNECTION']);

//当前请求的 Accept: 头部的内容。//
echo('34. HTTP_ACCEPT='.$_SERVER['HTTP_ACCEPT']);

//当前请求的 Accept-Encoding: 头部的内容      
echo('35. HTTP_ACCEPT_ENCODING='.$_SERVER['HTTP_ACCEPT_ENCODING']);

//浏览器语言
echo('36. HTTP_ACCEPT_LANGUAGE='.$_SERVER['HTTP_ACCEPT_LANGUAGE']);

//当前请求的 Host: 头部的内容。
echo('37. HTTP_HOST='.$_SERVER['HTTP_HOST']);

//链接到当前页面的前一页面的 URL 地址。       
echo('38. HTTP_REFERER='.$_SERVER['HTTP_REFERER']);

//当前请求的 User_Agent: 头部的内容。    
echo('39. HTTP_USER_AGENT='.$_SERVER['HTTP_USER_AGENT']);

//系统是多少位
echo('40. HTTP_UA_CPU='.$_SERVER['HTTP_UA_CPU']);

         
echo('41. HTTP_X_REWRITE_URL='.$_SERVER['HTTP_X_REWRITE_URL']);

//保存了发起该请求时刻的时间戳
echo('42. REQUEST_TIME='.$_SERVER['REQUEST_TIME']);  echo('<br>')        

//当前请求的 Accept-Charset: 头部的内容
echo('43. HTTP_ACCEPT_CHARSET="'.$_SERVER['HTTP_ACCEPT_CHARSET'].'"');  echo('<br>');

输出结果
1 . ALL_HTTP="HTTP_CONNECTION:Keep-Alive HTTP_ACCEPT:*/* HTTP_ACCEPT_ENCODING:gzip, deflate HTTP_ACCEPT_LANGUAGE:zh-cn HTTP_COOKIE:lang=DEF_LANG; __utma=217393494.1765278662.1262674713.1262763957.1262765762.10; __utmz=217393494.1262674713.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none); __utmc=217393494 HTTP_HOST:192.*.*.*:85 HTTP_USER_AGENT:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 2.0.50727) HTTP_UA_CPU:x86 HTTP_X_REWRITE_URL:/test/phpTest.php?id=2222&name=name1 "
2 . HTTPS="off"
3 . SCRIPT_NAME="/test/phpTest.php"
4 . HTTP_COOKIE="lang=DEF_LANG; __utma=217393494.1765278662.1262674713.1262763957.1262765762.10; __utmz=217393494.1262674713.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none); __utmc=217393494"
5 . AUTH_PASSWORD=""
6 . AUTH_TYPE=""
7 . AUTH_USER=""
8 . CONTENT_LENGTH="0"
9 . CONTENT_TYPE=""
10. PATH_TRANSLATED="E:\php"
11. QUERY_STRING="id=2222&name=name1"
12. REMOTE_ADDR="192.*.*.*"
13. REMOTE_HOST="192.*.*.*"
14. REMOTE_USER=""
15. REQUEST_METHOD="GET"
16. SERVER_NAME="192.*.*.*"
17. SERVER_PORT="85"
18. SERVER_PROTOCOL="HTTP/1.1"
19. SERVER_SOFTWARE="Microsoft-IIS/6.0"
20. APPL_MD_PATH="/LM/W3SVC/823433/Root"
21. APPL_PHYSICAL_PATH="E:\php\"
22. INSTANCE_ID="823433"
23. INSTANCE_META_PATH="/LM/W3SVC/823433"
24. LOGON_USER=""
25. REQUEST_URI="/test/phpTest.php?id=2222&name=name1"
26. URL="/test/phpTest.php?id=2222&name=name1"
27. SCRIPT_FILENAME="E:\php\test\phpTest.php"
28. ORIG_PATH_INFO="/test/phpTest.php"
29. PATH_INFO=""
30. ORIG_PATH_TRANSLATED="E:\php\test\phpTest.php"
31. DOCUMENT_ROOT="E:\php"
32. PHP_SELF="/test/phpTest.php"
33. HTTP_CONNECTION="Keep-Alive"
34. HTTP_ACCEPT="*/*"
35. HTTP_ACCEPT_ENCODING="gzip, deflate"
36. HTTP_ACCEPT_LANGUAGE="zh-cn"
37. HTTP_HOST="192.*.*.*:85"
38. HTTP_REFERER=""
39. HTTP_USER_AGENT="Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 2.0.50727)"
40. HTTP_UA_CPU="x86"
41. HTTP_X_REWRITE_URL="/test/phpTest.php?id=2222&name=name1"
42. REQUEST_TIME="1262770426"
43. HTTP_ACCEPT_CHARSET=""

 

 

1,$_SERVER["QUERY_STRING"] 
说明:查询(query)的字符串 

2,$_SERVER["REQUEST_URI"] 
说明:访问此页面所需的URI 

3,$_SERVER["SCRIPT_NAME"] 
说明:包含当前脚本的路径 

4,$_SERVER["PHP_SELF"] 
说明:当前正在执行脚本的文件名

 

实例: 
1,http://www.biuuu.com/ (直接打开主页) 
结果: 
$_SERVER["QUERY_STRING"] = “” 
$_SERVER["REQUEST_URI"] = “/” 
$_SERVER["SCRIPT_NAME"] = “/index.php” 
$_SERVER["PHP_SELF"] = “/index.php” 

2,http://www.biuuu.com/?p=222 (附带查询) 
结果: 
$_SERVER["QUERY_STRING"] = “p=222″ 
$_SERVER["REQUEST_URI"] = “/?p=222″ 
$_SERVER["SCRIPT_NAME"] = “/index.php” 
$_SERVER["PHP_SELF"] = “/index.php” 

3,http://www.biuuu.com/index.php?p=222&q=biuuu 
结果: 
$_SERVER["QUERY_STRING"] = “p=222&q=biuuu” 
$_SERVER["REQUEST_URI"] = “/index.php?p=222&q=biuuu” 
$_SERVER["SCRIPT_NAME"] = “/index.php” 
$_SERVER["PHP_SELF"] = “/index.php” 

$_SERVER["QUERY_STRING"]获取查询语句,实例中可知,获取的是?后面的值 
$_SERVER["REQUEST_URI"] 获取http://www.biuuu.com后面的值,包括/ 
$_SERVER["SCRIPT_NAME"] 获取当前脚本的路径,如:index.php 
$_SERVER["PHP_SELF"] 当前正在执行脚本的文件名

posted @ 2010-10-21 15:41  14叔  阅读(286)  评论(0编辑  收藏  举报