中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

php的web路徑獲取

2018-07-20    來源:open-open

容器云強(qiáng)勢上線!快速搭建集群,上萬Linux鏡像隨意使用
<?php
class HttpTool
{
    /**
     * //獲取域名或主機(jī)地址 
     * #測試網(wǎng)址:     http://localhost:8081/test/testurl.php?id=5
     * 返回  localhost:8081
     */
    public function getHost()
    {
        return $_SERVER['HTTP_HOST'];
    }
     
    /**
     * 當(dāng)前頁面的url(包括參數(shù))
     */
    public function getWebUrl()
    {
        $pageURL = 'http';
        if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on")
        {
            $pageURL .= "s";
        }
        $pageURL .= "://";
        $pageURL .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
        return $pageURL;
    }
     
    /**
     * 
     * 當(dāng)前頁面的url(不包括參數(shù))
     */
    public function getWebPath()
    {
        $pageURL = 'http';
        if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on")
        {
            $pageURL .= "s";
        }
        $pageURL .= "://";
        $pageURL .= $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
        return $pageURL;
    }
     
    /**
     * 當(dāng)前頁面的父路徑
     */
    public function getWebParentPath()
    {
        $pageURL = 'http';
        if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on")
        {
            $pageURL .= "s";
        }
        $pageURL .= "://";
        $pageURL .= $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
        $pageURL = substr($pageURL, 0, strrpos($pageURL, "/"));
        return $pageURL;
    }
     
    /**
     * 服務(wù)器名稱
     */
    public function getServerName()
    {
        return $_SERVER['SERVER_NAME'];
    }
     
    /**
     * 端口
     */
    public function getServerPort()
    {
        return $_SERVER["SERVER_PORT"];
    }
     
    /**
     * 鏈接參數(shù),問號?后的參數(shù)
     */
    public function getQueryString()
    {
        return $_SERVER['QUERY_STRING'];
    }
     
    /**
     * 請求地址,返回值不host內(nèi)容
     */
    public function getRequestUri()
    {
        return $_SERVER['REQUEST_URI'];
    }
}
 
$http = new HttpTool();
echo "host===============".$http->getHost() . "<br/>";
echo "weburl=============".$http->getWebUrl() . "<br/>";
echo "webPath============".$http->getWebPath() . "<br/>";
echo "getWebParentPath===".$http->getWebParentPath() . "<br/>";
echo "getServerName======".$http->getServerName() . "<br/>";
echo "getServerPort======".$http->getServerPort() . "<br/>";
echo "getQueryString=====".$http->getQueryString() . "<br/>";
echo "getRequestUri======".$http->getRequestUri() . "<br/>";
 
?>

測試地址:http://localhost:8081/test/httptool.php?name=penngo

輸出結(jié)果:

host===============localhost:8081
weburl=============http://localhost:8081/test/httptool.php?name=penngo
webPath============http://localhost:8081/test/httptool.php
getWebParentPath===http://localhost:8081/test
getServerName======localhost
getServerPort======8081
getQueryString=====name=penngo
getRequestUri======/test/httptool.php?name=penngo

標(biāo)簽: 服務(wù)器 域名

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:oc 文件管理NSFileManager,文件讀寫NSFileHandle 文件復(fù)制

下一篇: JS前臺加密,java后臺解密實現(xiàn)