Add Topic


waiting answer July 28, 2021

How to get current page URL in PHP

June 10, 2021

The built-in variable $_SERVER is used to get the current page URL in PHP. $_SERVER is a superglobal variable and it is available in all scopes. 

To get URI

        $uri = $_SERVER['REQUEST_URI'];
        echo $uri; 

To get the full URL

        $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
        $full_url = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
        echo $full_url; // This will output full url
0 0

Please Login to Post the answer

Leave an Answer