Home > Backend Development > PHP Tutorial > 使用PHP获取当前url路径的函数以及服务器变量_PHP

使用PHP获取当前url路径的函数以及服务器变量_PHP

WBOY
Release: 2016-06-01 12:05:15
Original
983 people have browsed it

PHP获取当前url路径的函数及服务器变量:
代码:
复制代码 代码如下:
$path = /usr/opt/../ect/abcd;
echo $_SERVER['DOCUMENT_ROOT']."
";   //获得服务器文档根变量(取决于http.conf中的配置)
echo $_SERVER['PHP_SELF']."
";  //获得执行该代码的文件的路径,与http.conf中的配置有关系。
echo __FILE__."
";  //获得文件的文件系统绝对路径的变量
echo dirname(__FILE__);  //获得文件所在的文件夹路径的函数
echo realpath($pah);
?>

返回的值:
复制代码 代码如下:
/usr/opt/apache2/htdocs/
/alias/aa.php
/usr/opt/apache2/htdocs/kamap/aa.php
/usr/opt/apache2/htdocs/kamap/
/usr/etc/abcd

Related labels:
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