I have created session and destroying session in logout.php but if i entered in url(http://localhost/demo/home.php)it showing loggedin.It should be redirect on index.php or display page not found.
What i am achieving- I have login section and there is no issue in that.I am able to login with my credentials and page is redirecting on home.php successfully.From home.php i have logout link and i clicked on that page is redirecting on index.php but if i entered home.php showing loggedin.. Please help me in this.
index.php
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
$sel_user = "SELECT * FROM admin WHERE Username='$username' and Password='$password'";
$run_user = mysqli_query($conn, $sel_user);
$check_user = mysqli_num_rows($run_user);
if($check_user>0){
echo "<script>window.open('home.php','_self')</script>";
$_SESSION['user_email']=$username;
}
else {
$msg="Username and Password is incorrect.";
}
Home.php
<h2>Home page</h2>
<a href="logout.php">logout</a>
logout.php
<?php
session_start();
if(session_destroy())
{
header("Location: index.php");
}
?>