获取PHP当前URL路径(Get current URL path in PHP)

2019-09-01 02:10发布

我需要从当前请求的URL获取路径。 例如,如果当前的网址是:

"http://www.example.com/example/test/hi.php?randomvariable=1"

我想这样的:

"/example/test/hi.php?randomvariable=1"

Answer 1:

你想$_SERVER['REQUEST_URI'] 。 从该文档 :

'REQUEST_URI'

这是为了访问此页面所需的URI。 例如, '/index.html'



Answer 2:

它应该是 :

$_SERVER['REQUEST_URI'];

看一看: 获取PHP的完整URL



Answer 3:

<?php
function current_url()
{
    $url      = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    $validURL = str_replace("&", "&amp", $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
}
?>


文章来源: Get current URL path in PHP
标签: php url