在php中,头函数无法正常使用会话销毁


Header function no work properly with session destroy in php

我试图通过下面的代码在注销后进入索引页,但它会占用我的页面,哪个页面包含注销代码。

通过此代码调用注销页面

<a href="logout.php">
    <span class="gly glyphicon glyphicon-log-out"></span>Log Out
</a>

注销代码

session_start();
session_destroy();
header('location : index.php');

注销后单击它将带我到"http://localhost/check/logout.php"页面,

根据您的文件结构,在logout.php所在的文件夹(或重写)中,由于您的锚点,您将被重定向到该页面。在您的锚点中的logout.php之前添加一个斜线"/",以转到localhost/logout.php。

如果文件已解决(您的问题有点模糊),并且您没有被重定向,这是由于您定义的标头。您应该将位置的第一个字母大写,以执行propper重定向。

 header('Location: index.php');