THINKPHP5获取当前页面URL信息
2024-08-22 11:22
PHP
130
1
1
0
标题录入
封面图
借助thinkphp 自带的request 类来获取当前的url信息 使用thinkRequest类 ``` $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_STRING echo '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: http://test.cn file: /index.php url: /index/index/hello.html?name=yourname url with domain: http://test.cn/index/index/hello.html?name=yourname url without query: /index/index/hello.html root: root with domain: http://yourname.cn pathinfo: index/index/hello.html pathinfo: index/index/hello ext: html ```
上一篇:
PHP 开发经验
下一篇:
延长phpmyadmin登录逾期时间的方法
标题录入,一次不能超过6条
怎么运用逻辑思维进行推理?
T:0.006452s,M:245.75 KB
返回顶部
留言
留言
评论