Php 如何完全销毁会话。如果会话不可用,则调用重定向到登录页面
您好,我试图破坏会话时,我按下注销按钮,然后它的登录和重定向到登录页面;但Php 如何完全销毁会话。如果会话不可用,则调用重定向到登录页面,php,jquery,ajax,session,redirect,Php,Jquery,Ajax,Session,Redirect,您好,我试图破坏会话时,我按下注销按钮,然后它的登录和重定向到登录页面;但当在浏览器中单击“上一步”时,该页面正在加载,且loign菜单位于顶部。 我在everypage中编写了一个代码,好像会话不可用,重定向到登录页面 以下是我的会话注销代码: elseif(isset($_GET['type']) && $_GET['type']== "logout" ) { if (!isset($_SESSION['id'])) { header('locatio
当在浏览器中单击“上一步”时,该页面正在加载,且loign菜单位于顶部。
我在everypage中编写了一个代码,好像会话不可用,重定向到登录页面
以下是我的会话注销代码:
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');
}
所以我的问题是,如果按back键,它将无法加载,并且必须重定向到登录页面,则完全注销。请尝试以下方法:
session_start();
unset($_SESSION["id"]);
session_destroy();
header('location:index');
试着这样做:
session_start();
unset($_SESSION["id"]);
session_destroy();
header('location:index');
通过此功能,您可以在浏览器上销毁所有会话。如果您使用php,您应该编写:
ob_start ();
session_start();
这样,您的缓冲区也将刷新并启动新会话。试试看
<?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,您应该编写:
ob_start ();
session_start();
这样,您的缓冲区也将刷新并启动新会话。试试看。
<?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
?>
创建一个类似于signout.php的页面,并设置signout按钮链接到此页面 示例
<a href="signout.php">Signout</a>
这应该适合你 创建一个类似于signout.php的页面,并将signout按钮链接设置到此页面 示例
<a href="signout.php">Signout</a>
这应该适合你 你添加标题了吗?像
过期、上次修改、缓存控制
?添加了头吗?如过期、上次修改、缓存控制?@baherbagh。。没关系。我只举了一个例子。但重要的是ob_start()的用法。@baherbagh。。没关系。我只举了一个例子。但重要的是ob_start()的使用。