信息发布→ 登录 注册 退出

thinkphp5怎么获取请求过来的网址

发布时间:2022-12-20

点击量:
thinkphp5获取请求网址的方法:1、使用“\think\Request”类的“$request = Request::instance();”方法获取当前的url信息;2、通过自带的助手函数“$request->url()”获取包含域名的完整URL地址。

本教程操作环境:Windows10系统、thinkphp5版、Dell G3电脑。

thinkphp5怎么获取请求过来的网址?

THINKPHP5获取当前页面URL信息

想要获取当前页面的url信息,可以借助thinkphp 自带的request 类来获取当前的url信息

使用\think\Request类

$request = Request::instance();

或者使用自带的助手函数

$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

推荐学习:《thinkPHP视频教程》

标签:# 不含  # 自带  # xmlns  # svg  # http  # Dell  # strong  # path  # display  # stroke  
在线客服
服务热线

服务热线

4008888355

微信咨询
二维码
返回顶部
×二维码

截屏,微信识别二维码

打开微信

微信号已复制,请打开微信添加咨询详情!