在 PHP 中获取当前 URL 路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16198790/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 10:42:25 来源:igfitidea点击:
Get current URL path in PHP
提问by totallyuneekname
I need to get the path from the URL of the current request. For example, if the current URL is:
我需要从当前请求的 URL 中获取路径。例如,如果当前 URL 是:
"http://www.example.com/example/test/hi.php?randomvariable=1"
I would want this:
我想要这个:
"/example/test/hi.php?randomvariable=1"
回答by Adrian
回答by Mehdi Karamosly
回答by manip5595
<?php
function current_url()
{
$url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$validURL = str_replace("&", "&", $url);
return $validURL;
}
//echo "page URL is : ".current_url();
$offer_url = current_url();
?>
<?php
if ($offer_url == "checking url name") {
?> <p> hi this is manip5595 </p>
<?php
}
?>