douzhoubing2805 2012-10-14 12:32
浏览 76
已采纳

在PHP注销后页面不重定向

I have two situation, currently I'm run my script from two different places with same script, first from localhost and second from website. The problem is when I run locally it logout successfully, it will redirect to index.php but why when I run at website it's not 100% working? The logout function is working but it's not redirect to index.php, It still appear the same page not index.php page.

My Logout Code as below:

<a href="<?php echo $logoutAction ?>">[Logout]</a>

My Session Code as below:

<?php
//initialize the session
if (!isset($_SESSION)) {
  session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  $_SESSION['MM_Username'] = NULL;
  $_SESSION['MM_UserGroup'] = NULL;
  $_SESSION['PrevUrl'] = NULL;
  unset($_SESSION['MM_Username']);
  unset($_SESSION['MM_UserGroup']);
  unset($_SESSION['PrevUrl']);

  $logoutGoTo = "index.php";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>
  • 写回答

4条回答 默认 最新

  • duanchuang1935 2012-10-14 12:50
    关注

    Finally, I found it by myself, the simple code that I found is:

    <?php
    session_start(); //Start the current session
    session_destroy(); //Destroy it! So we are logged out now
    header("location:index.php?msg=logout");
    ?>
    

    Anyway, thanks to all of you that want to try to help me. thanks so much!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog