[英]How to use php header() to redirect to homepage?
I have a link in my dashboad
page( http://localhost/dashboard.php
).我的仪表板页面中有一个链接( dashboad
http://localhost/dashboard.php
)。 The link is as following:链接如下:
<a class="nav-link" href="logout.php">
<img class="icon mb-n1px" src="assets/icons/sign_out.svg" alt="category icon">
Log Out
</a>
In the logout.php
file, I have the following code:在logout.php
文件中,我有以下代码:
<?php
session_unset();
header("Location: /");
exit();
?>
So clicking on that link the user agent is redirected to http://localhost/
.因此,单击该链接,用户代理将重定向到http://localhost/
。 I want to redirect to http://localhost
without the trailing slash.我想重定向到http://localhost
没有斜杠。 My question is我的问题是
header("Location: ");
为什么header("Location: ");
not work?不行?header("Location: ../");
为什么header("Location: ../");
still lead to http://localhost/
.仍然导致http://localhost/
。header("Location: /../");
为什么header("Location: /../");
doesn't remove the trailing slash?不删除尾部斜杠?PS: I have read the official docs https://www.php.net/manual/en/function.header.php and other SO posts but didn't find any explanation. PS:我已阅读官方文档https://www.php.net/manual/en/function.header.php和其他 SO 帖子,但没有找到任何解释。
You can use absolute url header("Location: http://localhost");
您可以使用绝对 url header("Location: http://localhost");
http://localhost
and http://localhost/
are equal因为http://localhost
和http://localhost/
是相等的/
因为那时没有上层/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.