Current page URL using PHP code?

This post explains how to get the current page url using simple php code. Check the below function will generate the current page URL.

    function currentPageURL() {
    $curpageURL = "http";
    if ($_SERVER["HTTPS"] == "on") {$curpageURL.= "s";}
    $curpageURL.= "://";
    if ($_SERVER["SERVER_PORT"] != "80") {
    } else {
        $curpageURL.= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
        return $curpageURL;

   echo currentPageURL();

Anil Kumar Panigrahi

With more than 10 years experience in PHP and Founder of Anil Labs, a blog for PHP and related posts. contributed posts regarding CodeIgniter, CakePHP and Learn PHP online ... Contact : [email protected]

You may also like...

6 Responses

  1. The code was really helpful to me. And it is easy to get the URL name. Thanks for the code.

  2. Vidhi says:

    Its done!!and most thing i understand the code easily..


  3. online resource says:


  4. vainfotech says:

    It is very usefull for me


  5. Mohit Bumb says:

    $_SERVER is really very useful global array. Get too much more info with var_dump($_SERVER);

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.