thinkphp5获取请求网址的方法:1、使用“ hinkRequest”类的“$request = Request::instance();”方法获取当前的url信息;2、通过自带的助手函数“$request->url()”获取包含域名的完整URL地址。
THINKPHP5获取当前页面URL信息
想要获取当前页面的url信息,可以借助thinkphp 自带的request 类来获取当前的url信息
使用 hinkRequest类
$request = Request::instance();
登录后复制
或者使用自带的助手函数
立即学习“PHP免费学习笔记(深入)”;
$request = request();
登录后复制$request = Request::instance();
// 获取当前域名
echo 'domain: ' . $request->domain() . '
';
// 获取当前入口文件
echo 'file: ' . $request->baseFile() . '
';
// 获取当前URL地址 不含域名
echo 'url: ' . $request->url() . '
';
// 获取包含域名的完整URL地址
echo 'url with domain: ' . $request->url(true) . '
';
// 获取当前URL地址 不含QUERY_STRING
echo 'url without query: ' . $request->baseUrl() . '
';
// 获取URL访问的ROOT地址
echo 'root:' . $request->root() . '
';
// 获取URL访问的ROOT地址
echo 'root with domain: ' . $request->root(true) . '
';
// 获取URL地址中的PATH_INFO信息
echo 'pathinfo: ' . $request->pathinfo() . '
';
// 获取URL地址中的PATH_INFO信息 不含后缀
echo 'pathinfo: ' . $request->path() . '
';
// 获取URL地址中的后缀信息
echo 'ext: ' . $request->ext() . '
';登录后复制输出结果domain: https://luweipai.cn
file: /index.php
url: /index/index/hello.html?name=luweipai
url with domain: https://luweipai.cn/index/index/hello.html?name=luweipai
url without query: /index/index/hello.html
root:
root with domain: http://luweipai.cn
pathinfo: index/index/hello.html
pathinfo: index/index/hello
ext: html登录后复制以上就是thinkphp5如何获取请求过来的网址的详细内容,更多请关注php中文网其它相关文章!
AmandaIncaboraa10 天前
发表在:关于我们"我很想找出激励你的东西。 和我聊天 h...
AmandaIncabora214 天前
发表在:关于我们我在等你的留言! 过来打个招呼! ...
AmandaIncaborac24 天前
发表在:关于我们让我们今晚难忘...你的地方还是我的? ...
BryanDen1 个月前
发表在:关于我们Самый быстрый и безо...
91资源网站长-冰晨6 个月前
发表在:【账号直充】爱奇艺黄金VIP会员『1个月』官方直充丨立即到账丨24小时全天秒单!不错不错,价格比官方便宜
91资源网站长-冰晨6 个月前
发表在:2022零基础Java入门视频课程不错,学习一下