想要获取当前页面的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