Current page URL using PHP code?

in PHP, PHP Code / 6 Comments

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

With more than 8 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]

Discussion 6 Comments

  1. Vidhi

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


Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>