dousong5161 2016-10-05 04:53
浏览 65
已采纳

我怎么能完全破坏会话。 如果会话不可用则重定向到登录页面

Hello i am trying to destory session when i press signout button then it's logging out and redirecting to login page; but when click back in browser that page is loading with loign menu on top.

And i have wrote a code in everypage as if session not available redirect to login page.

Here is my logout code for session_destroy:

elseif(isset($_GET['type']) && $_GET['type']== "logout" )
{
    if (!isset($_SESSION['id'])) {
        header('location:index.php');
        } else {
        session_destroy();
        $_SESSION = array(); 
        header('location:index.php');
    }
}

here is the code what i have mentioned in all pages:

session_start();
include_once('includes/config.php');
if(!isset($_SESSION['id'])) {
    header('location:login.php');
}

So my question is completly logout if press back it should not load and has to redirect to login page.

  • 写回答

4条回答 默认 最新

  • duanhuang4841 2016-10-05 05:10
    关注
    <?php
    session_start();
    if($_SESSION['id']){
    unset($_SESSION['id']); // destroys the specified session.
    
    }
    
    header('Location:index.php'); //redirect to preferred page after unset the session
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏