In this post we will show you  How to Get Current URL in PHP. $_SERVER is a superglobal variable in PHP, that provides information about headers, paths, and script locations. Besides the various uses of $_SERVER variable, it helps to get current page URL in PHP.

You can use $_SERVER variable to get current page URL in PHP. The following example code shows how to get current full URL with query string using $_SERVER variable in PHP.

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 $_SERVER['QUERY_STRING'].

(Visited 580 times, 1 visits today)