【发布时间】:2017-03-31 21:54:15
【问题描述】:
我在 session_start() 函数周围使用了一个特殊的包装类来为我的会话添加保护。
要注销用户,我有一个这样的按钮:
<a href="logout.php">
<button data-toggle="modal" data-backdrop="false" href="" name="out" class="btn btn-primary navbar-btn" style="margin-right: 3px"><span class="glyphicon glyphicon-user"></span>Log Out</button></a>
这里是logout.php:
<?php
error_reporting(0);
include('SessionManager.php');
$mySess = new SessionManager();
$session = $mySess -> sessionStart('InstallationName'); // create/start a new session or start the existent session
$mySess -> destroy(); //destroy the session
header('Location: page1bis.php');
exit();
?>
这是我的 SessionManager 类中的 destroy() 函数:
<?php
class SessionManager
{
.
.
.
static protected function destroy()
{
echo $_SESSION['cook'];echo "<br>";
echo "hello !";
session_destroy();
echo $_SESSION['cook'];
}
}
?>
但是当点击注销按钮时,它会进入lougout.php页面,但没有进行重定向,这里也是lougout.php的输出> 页面:
tfe0eccar02k3pgi5b7i8i2ek5
hello !
p.s: logout.php 中的回声只是在这里表明会话被有效地破坏(或者应该有 2 个令牌),也 即使我删除它们 strong> 还是一样的问题
【问题讨论】:
-
一旦你
echo'ed 任何东西,你就不能再发送标题了。您应该将控制流与输出分开。除此之外,您应该打开警告。 -
链接中不能有按钮。
-
确保
header()重定向位于页面的最顶部。在任何 HTML 之前。如果 HTML 先设置标题,header函数将无法生成标题。 -
顺便说一句
error_reporting(0);这对你的事业没有帮助。
标签: php