2
votes

I have a code a to do log out

The Problem is i can't header to index page after session_unset and session_destroy it stay in the page logout.php

i use ob_start(); and exit(); after the header

i also tried to use

header("Location:index.php");

also i tried to use

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

also i tried to use

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

also i tried to use

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

and i tried to echo the session after session_unset and session destroy nothing appear if i print the session before that i have the value of the session if i click back on the browser button i return back without any problem This my logout code

<?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();
?>

Can some help to fixed this problem ??!!

1
header('Refresh: 1; URL=index.php');RïshïKêsh Kümar
@RïshïKêshKümar Thank you for you reply but i didn't work nothing happen it still in the logout pagemohamad mohamad
ob_end_flush(); ?? what is this ...RïshïKêsh Kümar
@RïshïKêshKümar it solve it now thank youmohamad mohamad
by using this header('Refresh: 1; URL=index.php');mohamad mohamad

1 Answers

1
votes

Used This :

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