Home > Backend Development > PHP Tutorial > PH gets the current url path and server path summary (url gets the current path server path), ph current path_PHP tutorial

PH gets the current url path and server path summary (url gets the current path server path), ph current path_PHP tutorial

WBOY
Release: 2016-07-13 10:03:55
Original
1352 people have browsed it

PH gets the current url path and server path summary (url gets the current path server path), ph current path

The following are some of the ways to get the path in php A little knowledge, hope it helps you!

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/(Open the homepage directly) Result: $_SERVER["QUERY_STRING"] = "" $_SERVER["REQUEST_URI"] = "/" $_SERVER[ "SCRIPT_NAME"] = "/index.php" $_SERVER["PHP_SELF"] = "/index.php"

demo: 2
http://www.xxx.com/?p=1 (with query) Result: $_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 Result: $_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"] gets the query statement. It can be seen from the example that the value after ? is obtained. $_SERVER["REQUEST_URI"] obtains the value after http://www.xxx.com, including / $_SERVER ["SCRIPT_NAME"] Get the path of the current script, such as: index.php $_SERVER["PHP_SELF"] The file name of the currently executing script

Current url: "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']

To summarize, for QUERY_STRING, REQUEST_URI, SCRIPT_NAME and PHP_SELF, an in-depth understanding will help us correctly call these four values ​​​​in the $_SERVER function. Learn the differences between the four variables QUERY_STRING, REQUEST_URI, SCRIPT_NAME and PHP_SELF in the $_SERVER function through detailed examples.

$_SERVER["REQUEST_URI"]: Get the complete URL of the current request [except domain name]

The arrangement is slightly unclear, please point out...

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/967694.htmlTechArticlePH gets the current url path and server path summary (url gets the current path server path), ph current path is summarized below Some little knowledge about getting paths in php, I hope it can be helpful to you...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template