如何在 php 中一致地从查询中检索路径信息? (/index.php/foo/bar)
基本上,如果用户请求:
index.php/foo/bar
我需要“/foo/bar”,而
index.php
我需要“”或“/”,
我在谷歌上找不到任何信息,因为我不知道这叫什么(路径信息让我得到了路径信息) () 函数)
我发现 PHP_SELF 在有路径信息的情况下返回的结果与没有路径信息的情况不同
Basically if the user requests:
index.php/foo/bar
I need "/foo/bar" and for
index.php
I need "" or "/"
I couldn't find any information on google because I don't know what this is called (path info got me the pathinfo() function)
I found PHP_SELF returns differently if there is path info than if there is no info
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
文件名
/index.php
之后的部分称为路径信息(请参阅Apache 的AcceptPathInfo
指令)。您可以使用$_SERVER['PATH_INFO']< 访问该信息/代码>变量
。如果您想要带有查询的完整请求 URL 路径,请使用
$_SERVER['REQUEST_URI']
。The portion after your file name
/index.php
is called the path info (see Apache’sAcceptPathInfo
directive). You can access that information with the$_SERVER['PATH_INFO']
variable. And if you want the full requested URL path with query, use$_SERVER['REQUEST_URI']
.