(相關資料圖)
本教程操作環境:Windows10系統、thinkphp5版、Dell G3電腦。
thinkphp5怎么獲取請求過來的網址?
THINKPHP5獲取當前頁面URL信息
想要獲取當前頁面的url信息,可以借助thinkphp 自帶的request 類來獲取當前的url信息
使用\think\Request類
$request = Request::instance();
或者使用自帶的助手函數
$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_STRINGecho "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/>";
輸出結果
domain: https://luweipai.cnfile: /index.phpurl: /index/index/hello.html?name=luweipaiurl with domain: https://luweipai.cn/index/index/hello.html?name=luweipaiurl without query: /index/index/hello.htmlroot:root with domain: http://luweipai.cnpathinfo: index/index/hello.htmlpathinfo: index/index/helloext: html
推薦學習:《thinkPHP視頻教程》
以上就是thinkphp5怎么獲取請求過來的網址的詳細內容,更多請關注php中文網其它相關文章!
關鍵詞: ThinkPHP5