135

I need to get the path from the URL of the current request. For example, if the current URL is:

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

I would want this:

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

3 回答 3

253

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

'REQUEST_URI'

为访问此页面而提供的 URI;例如,'/index.html'

于 2013-04-24T17:47:08.760 回答
41

它应该是 :

$_SERVER['REQUEST_URI'];

看看:Get the full URL in PHP

于 2013-04-24T17:48:43.070 回答
7
<?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
}
?>
于 2018-07-27T05:54:31.703 回答