I-M-JM I-M-JM - 2 months ago 6
PHP Question

getting current URL

I am using following code to get the current URL

$current_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];


Is there any other way to get the same, or may be better way to get current URL?

Thanks.

Answer
  <?php
    function 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;
    }
    ?>