[英]PHP - Getting Current URL
This seems like a common questions but none of them seem to be what i'm looking for.这似乎是一个常见的问题,但似乎没有一个是我正在寻找的。 If there is a website:
如果有网站:
www.example.com/test.php
I want to pull the test.php
and if it's something like:我想拉
test.php
,如果它是这样的:
www.example.com/folder/folder1/test.php
I want again to just pull test.php
but everything seems to pull the exact path instead of just the page.我想再次拉
test.php
但一切似乎拉确切的路径,而不仅仅是页面。 Any suggestions?有什么建议?
$query = $_SERVER['PHP_SELF'];
$path = pathinfo( $query );
$what_you_want = $path['basename'];
Voila.瞧。
This will get you the name of the file that was requested (based on the URL invoked, not real location of the file - just in case you are using mod_rewrite):这将为您提供所请求文件的名称(基于调用的 URL,而不是文件的真实位置 - 以防万一您使用的是 mod_rewrite):
$filename = basename($_SERVER['REQUEST_URI']);
For both http://www.example.com/testing01.php
and http://www.example.com/x/y/z/testing01.php
will give you:对于
http://www.example.com/testing01.php
和http://www.example.com/x/y/z/testing01.php
都会给你:
testing01.php
$file = $_SERVER["SCRIPT_NAME"];
$break = explode('/', $file);
$pfile = $break[count($break) - 1];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.