php服务器request_uri忽略了URL最后一次斜线之后
我正在尝试使用PHP获取当前页面URL,并且某种程度上无法正常工作。这是我现在正在使用的代码,
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on')
$url = "https://";
else
$url = "http://";
$url.= $_SERVER['HTTP_HOST'];
$url.= $_SERVER['REQUEST_URI'];
echo $url;
我将通过一个URL,例如https://example.com/a
即使在URL结束时使用/a
https://example.com
和不是
https://example.com/a
当URL在上一个斜线之后包含多个字符时,它正在与正确的URL相呼应,例如https://example.com/aa
您可以请让我知道为什么会发生这种情况以及如何解决这个问题?
I am trying to get current page URL using PHP and somehow it is not working properly. Here is the code that I am using
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on')
$url = "https://";
else
$url = "http://";
$url.= $_SERVER['HTTP_HOST'];
$url.= $_SERVER['REQUEST_URI'];
echo $url;
Now I pass a URL like https://example.com/a
even with /a
at the end of URL I am still getting
https://example.com
and NOT
https://example.com/a
It is echoing correct URL when URL contains more than one characters after last slash like https://example.com/aa
Can you please let me know why this is happening and how I can fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论