获取当前文件的文件名,获取去当前文件的url路由地址

//获取当前文件名
function GetCurUrl()
{
    if(!empty($_SERVER["REQUEST_URI"]))
    {
        $scriptName = $_SERVER["REQUEST_URI"];
        $nowurl = $scriptName;
    }
    else
    {
        $scriptName = $_SERVER["PHP_SELF"];
        if(empty($_SERVER["QUERY_STRING"]))
        {
            $nowurl = $scriptName;
        }
        else
        {
            $nowurl = $scriptName."?".$_SERVER["QUERY_STRING"];
        }
    }
    return $nowurl;
}

$url=$HTTP_SERVER_VARS[‘REQUEST_URI‘];
echo(str_replace(‘/‘,‘‘,$url));

$url = $_SERVER[‘PHP_SELF‘];
$filename= substr( $url , strrpos($url , ‘/‘)+1 );
echo $filename;

$url = $_SERVER[‘PHP_SELF‘];
$arr = explode( ‘/‘ , $url );
$filename= $arr[count($arr)-1];
echo $filename;

$url = $_SERVER[‘PHP_SELF‘];
$filename = end(explode(‘/‘,$url));
echo $filename;
//获取当前文件的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;
}


echo curPageURL();

 

// 说明:获取无参数URL

function curPageURLL()
{
    $pageURL = ‘http‘;

    if ($_SERVER["HTTPS"] == "on")
    {
        $pageURL .= "s";
    }
    $pageURL .= "://";

    $this_page = $_SERVER["REQUEST_URI"];

    // 只取 ? 前面的内容
    if (strpos($this_page, "?") !== false)
        $this_page = reset(explode("?", $this_page));

    if ($_SERVER["SERVER_PORT"] != "80")
    {
        $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $this_page;
    }
    else
    {
        $pageURL .= $_SERVER["SERVER_NAME"] . $this_page;
    }
    return $pageURL;
}
echo curPageURLL();
echo ‘<br/>‘;
// 说明:获取无参数URL

function curPageURLLL()
{
    $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;
}

echo curPageURLLL();
//获取域名或主机地址
echo $_SERVER[‘HTTP_HOST‘].‘<br/>‘; #localhost

//获取网页地址
echo $_SERVER[‘PHP_SELF‘]."<br/>"; #/blog/testurl.php
//获取网址参数
echo $_SERVER["QUERY_STRING"]."<br/>"; #id=5
//获取用户代理
echo $_SERVER[‘HTTP_REFERER‘]."<br/>";
//获取完整的url
echo ‘http://‘.$_SERVER[‘HTTP_HOST‘].$_SERVER[‘REQUEST_URI‘]."<br/>";
echo ‘http://‘.$_SERVER[‘HTTP_HOST‘].$_SERVER[‘PHP_SELF‘].‘?‘.$_SERVER[‘QUERY_STRING‘]."<br/>";
#http://localhost/blog/testurl.php?id=5
//包含端口号的完整url
echo ‘http://‘.$_SERVER[‘SERVER_NAME‘].‘:‘.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]."<br/>";
#http://localhost:80/blog/testurl.php?id=5
//只取路径
$url=‘http://‘.$_SERVER[‘SERVER_NAME‘].$_SERVER["REQUEST_URI"];
echo dirname($url);

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。