1,$_SERVER["QUERY_STRING"]
说明:查询(query)的字符串2,$_SERVER["REQUEST_URI"]
说明:访问此页面所需的URI3,$_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"] 当前正在执行脚本的文件名
当前url:"http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']
总结一下,对于QUERY_STRING,REQUEST_URI,SCRIPT_NAME和PHP_SELF,深入了解将有利于我们在$_SERVER函数中正确调用这四个值。通过实例详解$_SERVER函数中QUERY_STRING,REQUEST_URI,SCRIPT_NAME和PHP_SELF掌握四个变量之间的区别。
$_SERVER["REQUEST_URI"] :获取当前请求的完整的(除域名的)url。。。
uchome系统中处理技巧:
代码 Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->//处理REQUEST_URIif(!isset($_SERVER['REQUEST_URI'])) { $_SERVER['REQUEST_URI'] = $_SERVER['PHP_SELF']; if(isset($_SERVER['QUERY_STRING'])) $_SERVER['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];}if($_SERVER['REQUEST_URI']) { $temp = urldecode($_SERVER['REQUEST_URI']); if(strexists($temp, '<') || strexists($temp, '"')) { $_GET = shtmlspecialchars($_GET);//XSS }}
代码 Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> "; //获得服务器文档根变量echo $_SERVER['PHP_SELF'].""; //获得执行该代码的文件服务器绝对路径的变量echo __FILE__.""; //获得文件的文件系统绝对路径的变量echo dirname(__FILE__); //获得文件所在的文件夹路径的函数?>
//server函数
$_SERVER["HTTP_REFERER"]=http://localhost/lianxi/$_SERVER["HTTP_ACCEPT_LANGUAGE"]=zh-cn$_SERVER["HTTP_ACCEPT_ENCODING"]=gzip, deflate$_SERVER["HTTP_USER_AGENT"]=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727)$_SERVER["HTTP_HOST"]=localhost$_SERVER["HTTP_CONNECTION"]=Keep-Alive$_SERVER["PATH"]=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Common Files\Adobe\AGL;C:\Program Files\MySQL\MySQL Server 5.0\bin;C:\php;C:\php\ext$_SERVER["SystemRoot"]=C:\WINDOWS$_SERVER["COMSPEC"]=C:\WINDOWS\system32\cmd.exe$_SERVER["PATHEXT"]=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH$_SERVER["WINDIR"]=C:\WINDOWS$_SERVER["SERVER_SIGNATURE"]=Apache/2.0.55 (Win32) PHP/5.1.1 Server at localhost Port 80 \\使用的何服务器$_SERVER["SERVER_SOFTWARE"]=Apache/2.0.55 (Win32) PHP/5.1.1$_SERVER["SERVER_NAME"]=localhost \\服务器名称$_SERVER["SERVER_ADDR"]=127.0.0.1$_SERVER["SERVER_PORT"]=80 \\服务器端口$_SERVER["REMOTE_ADDR"]=127.0.0.1$_SERVER["DOCUMENT_ROOT"]=D:/lianxi \\网站的主目录$_SERVER["SERVER_ADMIN"]=sss@163.com \\安装APACHE时设置的邮箱$_SERVER["SCRIPT_FILENAME"]=D:/lianxi/lianxi/servervalues.php \\当前的网页的绝对路径,$_SERVER["REMOTE_PORT"]=1076 \\远程端口$_SERVER["GATEWAY_INTERFACE"]=CGI/1.1$_SERVER["SERVER_PROTOCOL"]=HTTP/1.1$_SERVER["REQUEST_METHOD"]=GET$_SERVER["QUERY_STRING"]=\\获取?号后面的内容$_SERVER["REQUEST_URI"]=例子:/lianxi/servervalues.php?a=1&b=2$_SERVER["SCRIPT_NAME"]=例子:/lianxi/servervalues.php$_SERVER["PHP_SELF"]=/lianxi/servervalues.php \\返回当前网页的相对路径.$_SERVER["REQUEST_TIME"]=1179190013 \\运行时间 单位为十万分之一毫秒$_SERVER["argv"]=Array$_SERVER["argc"]=01,$_SERVER["QUERY_STRING"]说明:查询(query)的字符串2,$_SERVER["REQUEST_URI"]说明:访问此页面所需的URI3,$_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"] 当前正在执行脚本的文件名