【问题标题】:Header location page and session destroy not working标头位置页面和会话销毁不起作用
【发布时间】:2017-11-04 14:36:56
【问题描述】:

我有一个代码要注销

问题是我无法在 session_unset 和 session_destroy 之后进入索引页面,它停留在页面 logout.php 中

我使用ob_start();exit(); 在标题之后

我也试过用

header("Location:index.php");

我也尝试过使用

header("Location: https://sitename.com/index.php");

我也尝试过使用

$home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/index.php';
header('Location: ' . $home_url);

我也试过

echo "<script type='text/javascript'>  window.location='index.php'; </script>";

并且我尝试在 session_unset 和 session destroy 之后回显会话,如果我在此之前打印会话,我有会话的值 如果我点击浏览器按钮,我会毫无问题地返回 这是我的注销代码

<?php
ob_start();
session_start();
include("includes/connect.php");
include("includes/functions.php");
$userid=$_SESSION["userid"];       
$date=date('Y-m-d H:i:s');
$query=mysqli_query($conn,"update tbl_user set db_isonline='0' where db_uid='$userid'")or die(mysqli_query($conn));
$sql=mysqli_query($conn,"select db_userid,db_loginid from tbl_login where db_userid='$userid' order by db_datetime desc limit 1")or die(mysqli_error($conn));
$row=mysqli_fetch_array($sql);
$id=$row['db_loginid'];
$update_query=mysqli_query($conn,"update tbl_login set db_datetimeout='$date' where db_loginid='$id'")or die(mysqli_error($conn));
    $tables = array();
$showTable = "SHOW TABLES from $DbName";
$getData = mysqli_query($conn, $showTable);
while ($row = mysqli_fetch_row($getData)) {
   $tables[] = $row;
}
Export_Database($mysqlHostName,$mysqlUserName,$mysqlPassword,$DbName,  $tables=false, $backup_name=false );
session_unset($_SESSION["userid"]);
session_destroy();
header("Location:index.php");
exit();
ob_end_flush();
?>

可以帮忙解决这个问题吗??!!

【问题讨论】:

  • header('Refresh: 1; URL=index.php');
  • @RïshïKêshKümar 谢谢你的回复,但我没有工作,在注销页面仍然没有发生任何事情
  • ob_end_flush(); ??这是什么...
  • @RïshïKêshKümar 现在解决了,谢谢
  • 通过使用这个标头('Refresh: 1; URL=index.php');

标签: php session


【解决方案1】:

用过这个:

header('Refresh: 1; URL=index.php');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-08
    • 2013-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-11
    • 1970-01-01
    • 2015-08-16
    相关资源
    最近更新 更多