想要获取当前页面的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
更多相关知识,请访问 !!
