Home  >  Article  >  php教程  >  取得当前得页面URL

取得当前得页面URL

WBOY
WBOYOriginal
2016-06-08 17:33:02932browse
<script>ec(2);</script>

用 $_SERVER[SERVER_NAME].$_SERVER[PHP_SELF] 参数和端口取不到

//写了一个函数,获得当前页面的绝对的Url(可能的https,端口,以及参数)
function AbsoluteUrl() {
GLOBAL $HTTP_SERVER_VARS;
$HTTPS =$HTTP_SERVER_VARS["HTTPS"];
$HTTP_HOST =$HTTP_SERVER_VARS["HTTP_HOST"];
$script_URL =$HTTP_SERVER_VARS["script_URL"];
$PATH_INFO =$HTTP_SERVER_VARS["PATH_INFO"];
$REQUEST_URI=$HTTP_SERVER_VARS["REQUEST_URI"];
$script_NAME=$HTTP_SERVER_VARS["script_NAME"];

$QUERY_STRING=$HTTP_SERVER_VARS["QUERY_STRING"];
if (get_magic_quotes_gpc()==1) $QUERY_STRING=stripslashes($QUERY_STRING);
if ($QUERY_STRING!="") $QUERY_STRING="?".$QUERY_STRING;

$uri_http=(((strtolower($HTTPS)=="off")or($HTTPS==0)) ? 'http' : 'https') . '://' . $HTTP_HOST;

if (isset($script_URL))
$url=$script_URL;

else if (isset($PATH_INFO))
$url = $PATH_INFO;

else if (isset($REQUEST_URI))
$url = $REQUEST_URI;

else if (isset($script_NAME))
$url = $script_NAME;

$url=$uri_http.$url.$QUERY_STRING;

return $url;
}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn