Home >Backend Development >PHP Tutorial >Use PHP to get the function of the current url path and server variables_PHP tutorial

Use PHP to get the function of the current url path and server variables_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:02:26946browse

PHP function and server variable to obtain the current url path:
Code:

Copy code The code is as follows:

$path = /usr/opt/../ect/abcd;
echo $_SERVER['DOCUMENT_ROOT']."
"; //Get the server document Root variable (depends on the configuration in http.conf)
echo $_SERVER['PHP_SELF']."
"; //Get the path to the file that executes the code, which is consistent with the configuration in http.conf relation.
echo __FILE__."
"; //Variable to get the file system absolute path of the file
echo dirname(__FILE__); //Function to get the folder path where the file is located
echo realpath( $pah);
?>

Returned value:
Copy code Code As follows:

/usr/opt/apache2/htdocs/
/alias/aa.php
/usr/opt/apache2/htdocs/kamap/aa.php
/ usr/opt/apache2/htdocs/kamap/
/usr/etc/abcd

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327929.htmlTechArticlePHP functions and server variables to obtain the current url path: Code: Copy the code as follows: ?php $path = / usr/opt/../ect/abcd; echo $_SERVER['DOCUMENT_ROOT']."br"; //Get the server document...
Statement:
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