您好,当我按下注销按钮时,我试图破坏 session ,然后它会注销并重定向到登录页面;但是当在浏览器中单击返回时,该页面正在加载,顶部有登录菜单。
我在每个页面都编写了一段代码,就好像 session 不可用重定向到登录页面一样。
这是我的 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');
}
}
这是我在所有页面中提到的代码:
session_start();
include_once('includes/config.php');
if(!isset($_SESSION['id'])) {
header('location:login.php');
}
所以我的问题是如果按回则完全注销,它不应该加载并且必须重定向到登录页面。
最佳答案
<?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
?>
关于php - 我怎样才能完全销毁 session 。如果 session 不可用,则重定向到登录页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39865680/