I am new to php and I am facing this problem i tried to solve this but was unable please need your help. I want to make users first login and then access other pages they should not directly access the other pages. when i add the code it is not making users to access other pages without logging in it redirect user to login but it is not working in traditional way like when i put login info it brings back login page.. sorry for bothering here is the code
<?php
// Start of Login Alert Code
if (!isset($_SESSION['user'])) {
$_SESSION['msg'] = "You must log in first";
header('location: login.php');
}
if (isset($_GET['logout'])) {
session_destroy();
unset($_SESSION['user']);
header("location: login.php");
}
?>
and here is code of login.php
<?php
if(isset($_POST['Login']))
{
$user = $_POST['uid'];
$pwd = $_POST['pass'];
$query = "SELECT * FROM users WHERE userid='$user' && password='$pwd'";
$data= mysqli_query($con,$query);
$total = mysqli_num_rows($data);
if($total==1)
{
$_SESSION ['user_id']= $user;
header('location:home.php');
}
else {
header('location:error.php');
}
}
?>