How to Get Current URL in PHP

In this tutorial, we will learn how to Get the Current URL in PHP. You can use the $_SERVER built-in variable to get the current page URL in PHP. The $_SERVER is a super global variable, which means it is always available in all scopes.
Use $_SERVER[‘HTTPS’] to check the protocol whether it is HTTP or HTTPS.
Use $_SERVER[‘HTTP_HOST’] to get header from the current request and $_SERVER[‘REQUEST_URI’] to get URI of the current page.
If you want to get current page URL with query string, use this $_SERVER[‘QUERY_STRING’].