How to get current page URL in PHP?

To get the current page URL, PHP provides a superglobal variable $_SERVER. The $_SERVER is a built-in variable of PHP, which is used to get the current page URL. It is a superglobal variable, means it is always available in all scope.

If we want the full URL of the page, then we'll need to check the protocol (or scheme name), whether it is https or http. See the example below:

Output

How to get current page URL in PHP

Note: The isset() function is used here to check whether HTTPS is enabled or not. It checks whether a variable exists or not.

Or, we can also get the full URL of current page using another way given in the next example.

Output

How to get current page URL in PHP 1

To get only name of the current page opened at browser, see the below example:

Output

How to get current page URL in PHP 1

Next TopicPHP Tutorial




Contact US

Email:[email protected]

Get Current Page URL
10/30