Your Ad Here

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();

You may like these posts

    Friendly file size for a file using php codeHow to send external html content mail using php?How to add image in joomla for each article sidebarHow to request a cross domain ajax with in the js file

 

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