Home > PHP > Current page URL using PHP code?

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") {
       $curpageURL.= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
    } else {
        $curpageURL.= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
        }
        return $curpageURL;
    }

   echo currentPageURL();
You may also like
Multi-language support for web application with MySql and PHP
How to add or remove file fields using jquery
How to calculate statistics in daily, weekly , monthly and yearly using php
How to rectify json_encode returns null in php web services

6 Responses

Leave a Reply

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