Home >Backend Development >PHP Tutorial >How Do I Get the Current Page\'s URL in PHP?
How to Retrieve the Current Page's URL in PHP
In PHP, determining the current page's URL is a simple task. To do so, leverage the $_SERVER['REQUEST_URI'] variable. This variable holds the portion of the URL after the domain name (e.g., http://domain.example).
For instance, if the current page's full URL is https://example.com/about-us, the $_SERVER['REQUEST_URI'] variable will return /about-us.
Additionally, if you require the query string (the parameters appended after the ? in the URL), it can be retrieved from $_SERVER['QUERY_STRING'].
Remember to refer to the PHP manual for the $_SERVER superglobal array for further information on the available details. Its documentation includes comprehensive explanations and examples that can guide you in working with other server variables.
The above is the detailed content of How Do I Get the Current Page\'s URL in PHP?. For more information, please follow other related articles on the PHP Chinese website!