THINKPHP5获取当前页面URL信息
2022-07-28 14:14:58
140
{{single.collect_count}}

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

如果您觉得本篇对你有帮助,可以点关注,给个赞,支持一下,过程有遇到什么问题也欢迎评论私信,进行交流

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}