thinkphp5如何獲取請求過來的網址

thinkphp5獲取請求網址的方法:1、使用“thinkRequest”類的“$request = Request::instance();”方法獲取當前的url信息;2、通過自帶的助手函數“$request->url()”獲取包含域名的完整URL地址。

THINKPHP5獲取當前頁面URL信息

想要獲取當前頁面的url信息,可以借助thinkphp 自帶的request 類來獲取當前的url信息

使用thinkRequest類

$request = Request::instance();<br>

或者使用自帶的助手函數

立即學習PHP免費學習筆記(深入)”;

$request = request();<br>
$request?=?Request::instance(); //?獲取當前域名 echo?'domain:?'?.?$request-&gt;domain()?.?'<br>'; //?獲取當前入口文件 echo?'file:?'?.?$request-&gt;baseFile()?.?'<br>'; //?獲取當前URL地址?不含域名 echo?'url:?'?.?$request-&gt;url()?.?'<br>'; //?獲取包含域名的完整URL地址 echo?'url?with?domain:?'?.?$request-&gt;url(true)?.?'<br>'; //?獲取當前URL地址?不含QUERY_STRING echo?'url?without?query:?'?.?$request-&gt;baseUrl()?.?'<br>'; //?獲取URL訪問的ROOT地址 echo?'root:'?.?$request-&gt;root()?.?'<br>'; //?獲取URL訪問的ROOT地址 echo?'root?with?domain:?'?.?$request-&gt;root(true)?.?'<br>'; //?獲取URL地址中的PATH_INFO信息 echo?'pathinfo:?'?.?$request-&gt;pathinfo()?.?'<br>'; //?獲取URL地址中的PATH_INFO信息?不含后綴 echo?'pathinfo:?'?.?$request-&gt;path()?.?'<br>'; //?獲取URL地址中的后綴信息 echo?'ext:?'?.?$request-&gt;ext()?.?'<br>';

輸出結果

domain: https://luweipai.cn<br>file: /index.php<br>url: /index/index/hello.html?name=luweipai<br>url with domain: https://luweipai.cn/index/index/hello.html?name=luweipai<br>url without query: /index/index/hello.html<br>root:<br>root with domain: http://luweipai.cn<br>pathinfo: index/index/hello.html<br>pathinfo: index/index/hello<br>ext: html

以上就是

? 版權聲明
THE END
喜歡就支持一下吧
點贊8 分享