thinkphp5獲取請求網(wǎng)址的方法:1、使用“thinkRequest”類的“$request = Request::instance();”方法獲取當前的url信息;2、通過自帶的助手函數(shù)“$request->url()”獲取包含域名的完整URL地址。
本教程操作環(huán)境:Windows10系統(tǒng)、thinkphp5版、Dell G3電腦。
thinkphp5怎么獲取請求過來的網(wǎng)址?
THINKPHP5獲取當前頁面URL信息
想要獲取當前頁面的url信息,可以借助thinkphp 自帶的request 類來獲取當前的url信息
立即學習“PHP免費學習筆記(深入)”;
使用thinkRequest類
$request?=?Request::instance();
或者使用自帶的助手函數(shù)
$request?=?request();
$request?=?Request::instance(); //?獲取當前域名 echo?'domain:?'?.?$request->domain()?.?'<br>'; //?獲取當前入口文件 echo?'file:?'?.?$request->baseFile()?.?'<br>'; //?獲取當前URL地址?不含域名 echo?'url:?'?.?$request->url()?.?'<br>'; //?獲取包含域名的完整URL地址 echo?'url?with?domain:?'?.?$request->url(true)?.?'<br>'; //?獲取當前URL地址?不含QUERY_STRING echo?'url?without?query:?'?.?$request->baseUrl()?.?'<br>'; //?獲取URL訪問的ROOT地址 echo?'root:'?.?$request->root()?.?'<br>'; //?獲取URL訪問的ROOT地址 echo?'root?with?domain:?'?.?$request->root(true)?.?'<br>'; //?獲取URL地址中的PATH_INFO信息 echo?'pathinfo:?'?.?$request->pathinfo()?.?'<br>'; //?獲取URL地址中的PATH_INFO信息?不含后綴 echo?'pathinfo:?'?.?$request->path()?.?'<br>'; //?獲取URL地址中的后綴信息 echo?'ext:?'?.?$request->ext()?.?'<br>';
輸出結(jié)果
domain:?https://luweipai.cn file:?/index.php url:?/index/index/hello.html?name=luweipai url?with?domain:?https://luweipai.cn/index/index/hello.html?name=luweipai url?without?query:?/index/index/hello.html root: root?with?domain:?http://luweipai.cn pathinfo:?index/index/hello.html pathinfo:?index/index/hello ext:?html
推薦學習:《thinkPHP視頻教程》
? 版權(quán)聲明
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載。
THE END