2011-09-06 99 views
0

我需要使用哪些變量來在瀏覽器中構建確切的URL?用PHP獲取整個網址?

例如[protocol][domain][path][get params]

,所以我希望能有一個變量包含http://example.com/folder/file.php?something=value

但我不知道是什麼$_SERVER變量我可以用它來建立這個字符串?

回答

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