How to get the current URL of web page in PHP

by Lechu on December 31, 2008

A simple function that I had used in the Translation Plugin, this could be your use. This is a PHP function which can get you the URL of the page being visited.

 

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

You can print the URL by using this function

  1. PHP Script to Validate URL : I have been working to create...
  2. Translate your web pages and get Google Indexed : I have written a WordPress Plugin...
  3. Converting text with link to hyperlink in PHP : I wanted to covert http texts...
  4. Modifying Image size for the home page – WordPress : I have done some modification for...
  5. Kish Translate WordPress Translation Plugin– Concept : I was really interested in developing...