Home > php教程 > php手册 > body text

PH获取当前url路径及服务器路径汇总 (url 获取当前路径 服务器路径),ph当前路径

WBOY
Release: 2016-06-13 09:12:15
Original
850 people have browsed it

PH获取当前url路径及服务器路径汇总 (url 获取当前路径 服务器路径),ph当前路径

以下是整理的一些, php中获取路径的小知识, 希望对你有所帮助!

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

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

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

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

  

demo: 1
http://www.xxx.com/(直接打开主页) 结果: $_SERVER["QUERY_STRING"] = "" $_SERVER["REQUEST_URI"] = "/" $_SERVER["SCRIPT_NAME"] = "/index.php" $_SERVER["PHP_SELF"] = "/index.php"

demo:2
http://www.xxx.com/?p=1 (附带查询) 结果: $_SERVER["QUERY_STRING"] = "p=1" $_SERVER["REQUEST_URI"] = "/?p=1" $_SERVER["SCRIPT_NAME"] = "/index.php" $_SERVER["PHP_SELF"] = "/index.php"

demo 3
http://www.xxx.com/index.php?p=1&q=xxx 结果: $_SERVER["QUERY_STRING"] = "p=1&q=xxx" $_SERVER["REQUEST_URI"] = "/index.php?p=1&q=xxx" $_SERVER["SCRIPT_NAME"] = "/index.php" $_SERVER["PHP_SELF"] = "/index.php"

$_SERVER["QUERY_STRING"]获取查询语句,实例中可知,获取的是?后面的值 $_SERVER["REQUEST_URI"] 获取http://www.xxx.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

整理的略有不详之处,请指出...

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template