thinkphp5如何获取请求过来的网址

来源:undefined 2024-12-29 00:16:02 1036

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

THINKPHP5获取当前页面URL信息

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

使用 hinkRequest类

1

$request = Request::instance();<br>

登录后复制

或者使用自带的助手函数

1

$request = request();<br>

登录后复制

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

$request = Request::instance();

// 获取当前域名

echo domain:  . $request-&gt;domain() . <br>;

// 获取当前入口文件

echo file:  . $request-&gt;baseFile() . <br>;

// 获取当前URL地址 不含域名

echo url:  . $request-&gt;url() . <br>;

// 获取包含域名的完整URL地址

echo url with domain:  . $request-&gt;url(true) . <br>;

// 获取当前URL地址 不含QUERY_STRING

echo url without query:  . $request-&gt;baseUrl() . <br>;

// 获取URL访问的ROOT地址

echo root: . $request-&gt;root() . <br>;

// 获取URL访问的ROOT地址

echo root with domain:  . $request-&gt;root(true) . <br>;

// 获取URL地址中的PATH_INFO信息

echo pathinfo:  . $request-&gt;pathinfo() . <br>;

// 获取URL地址中的PATH_INFO信息 不含后缀

echo pathinfo:  . $request-&gt;path() . <br>;

// 获取URL地址中的后缀信息

echo ext:  . $request-&gt;ext() . <br>;

登录后复制

输出结果

1

domain: https://luweipai.cn<br>file: /index.php<br>url: /index/index/hello.html?name=luweipai<br>url with domain: https://luweipai.cn/index/index/hello.html?name=luweipai<br>url without query: /index/index/hello.html<br>root:<br>root with domain: http://luweipai.cn<br>pathinfo: index/index/hello.html<br>pathinfo: index/index/hello<br>ext: html

登录后复制

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

最新文章