Home > php教程 > php手册 > 获取当前页面的url地址php代码

获取当前页面的url地址php代码

WBOY
Release: 2016-06-13 09:57:50
Original
1161 people have browsed it

获取当前页面的url地址php代码,第一款是一款获取无参数URL第二款是获取完整URL函数哦,如果你正找url参数的代码哦。

获取当前页面的url地址php教程代码,第一款是一款获取无参数url第二款是获取完整url函数哦,如果你正找url参数的代码哦。

 

// 说明:获取无参数url

function curpageurl()
{
    $pageurl = 'http';

    if ($_server["https教程"] == "on")
    {
        $pageurl .= "s";
    }
    $pageurl .= "://";

    if ($_server["server_port"] != "80")
    {
        $pageurl .= $_server["server_name"].":" . $_server["server_port"] . $_server['php_self'];
    }
    else
    {
        $pageurl .= $_server["server_name"] . $_server['php_self'];
    }
    return $pageurl;
}
?>

方法二

// 说明:获取完整url

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;
}
?>

另外,$_server['request_uri'] 和 $_server['request_url'] 是有稍微区别的:
$_server["request_uri"] 返回完整的路径 ( /directory/file.ext?query=string )
$_server['request_url'] 只返回文件路径,不包括参数,( /directory/file.ext ),和$_server['php_self']差不多,只不过在有些服务器上$_server['request_url']不可用

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template