繁体   English   中英

如何使用 php header() 重定向到主页?

[英]How to use php header() to redirect to homepage?

我的仪表板页面中有一个链接( dashboad http://localhost/dashboard.php )。 链接如下:

<a class="nav-link" href="logout.php">
  <img class="icon mb-n1px" src="assets/icons/sign_out.svg" alt="category icon"> 
  Log Out
</a>

logout.php文件中,我有以下代码:

<?php   
    session_unset();
    header("Location: /"); 
  exit();
?>

因此,单击该链接,用户代理将重定向到http://localhost/ 我想重定向到http://localhost没有斜杠。 我的问题是

  1. 为什么header("Location: "); 不行?
  2. 为什么header("Location: ../"); 仍然导致http://localhost/
  3. 为什么header("Location: /../"); 不删除尾部斜杠?

PS:我已阅读官方文档https://www.php.net/manual/en/function.header.php和其他 SO 帖子,但没有找到任何解释。

您可以使用绝对 url header("Location: http://localhost");

  1. 因为你需要指定你想重定向到哪里
  2. 因为http://localhosthttp://localhost/是相等的
  3. 因为那时没有上层/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM