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

来源:php中文网 | 2022-12-20 09:53:51 |


(相关资料图)

本教程操作环境: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() . "<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

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

以上就是thinkphp5怎么获取请求过来的网址的详细内容,更多请关注php中文网其它相关文章!

关键词: ThinkPHP5