Home » PHP, PHP Code »

6

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

1
2
3
4
5
6
7
8
9
10
11
12
13
    function currentPageURL() {
    $curpageURL = "http";
    if ($_SERVER["HTTPS"] == "on") {$curpageURL.= "s";}
    $curpageURL.= "://";
    if ($_SERVER["SERVER_PORT"] != "80") {
       $curpageURL.= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
    } else {
        $curpageURL.= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
        }
        return $curpageURL;
    }

   echo currentPageURL();

Related Posts

    Multi-language support for web application with MySql and PHPHow to get the real IP address using php?How to download a file using php codeSmall urls generated using php code?

 

6 Comments

  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..

    thanks.

  3. online resource says:

    Nice

  4. vainfotech says:

    It is very usefull for me

    Thanks

  5. Mohit Bumb says:

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

Leave a Reply