Get current URL path in PHP

122

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"

This question is tagged with php url

~ Asked on 2013-04-24 17:45:36

The Best Answer is


231

You want $_SERVER['REQUEST_URI']. From the docs:

'REQUEST_URI'

The URI which was given in order to access this page; for instance, '/index.html'.

~ Answered on 2013-04-24 17:47:08


37

it should be :

$_SERVER['REQUEST_URI'];

Take a look at : Get the full URL in PHP

~ Answered on 2013-04-24 17:48:43


Most Viewed Questions: