下面的一个是我的php网站中的链接..点击此按钮后,用户的会话应该被终止,他应该被重定向到主页..我已经编写了这个概念的编码如下,但它显示我只是一个空白页面(它没有重定向到主页).. 请更正我的编码
<a href="Logout.php">
click here to log out</a>
Logout.php中的编码如下
<?
session_start();
session_unset();
session_destroy();
ob_start();
header("location:home.php");
ob_end_flush();
include 'home.php';
//include 'home.php';
exit();
?>
答案 0 :(得分:56)
只有这是必要的
session_start();
unset($_SESSION["nome"]); // where $_SESSION["nome"] is your own variable. if you do not have one use only this as follow **session_unset();**
header("Location: home.php");
答案 1 :(得分:18)
请改用:
<?
session_start();
session_unset();
session_destroy();
header("location:home.php");
exit();
?>
答案 2 :(得分:6)
<?php
session_start();
session_destroy();
header("Location: home.php");
?>
答案 3 :(得分:3)
<?php
session_start();
session_unset();
session_destroy();
header("location:home.php");
exit();
?>
答案 4 :(得分:0)
<?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 variables
$_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;
}
} ?>
答案 5 :(得分:0)
注销并重定向回登录名或索引的最简单方法:
<?php
if (!isset($_SESSION)) { session_start(); }
$_SESSION = array();
session_destroy();
header("Location: login.php"); // Or wherever you want to redirect
exit();
?>