Get the path with query string on the current http request in PHP

php, url

Solution

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'`.

Problem

I need to get the path with query string 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" ```

Original source

Related problems