How to get URL of current page in PHP

php, url

Solution

$_SERVER['REQUEST_URI']

For more details on what info is available in the $_SERVER array, see the PHP manual page for it.

If you also need the query string (the bit after the `?` in a URL), that part is in this variable:

$_SERVER['QUERY_STRING']

Problem

In PHP, how can I get the URL of the current page? Preferably just the parts after `http://domain.example`.

Original source

Related problems