thinkphp5获取当前页面URL信息

想要获取当前页面的url信息,可以借助thinkphp 自带的request 类来获取当前的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_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: 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

原创文章,作者:ECHO陈文,如若转载,请注明出处:https://www.luweipai.cn/php/648156/

  • 0