I am writing a script to login a user (this will not be accessible from outside users) where a simple login form will suffice in logging a user in and setting a session.
I seem to be having an issue where it just redirects me back presumably because the session parameter isn't met but the login I am using exists and it will attempt to redirect to log me in. Here is my code, any help would excellent:
Login page
<form action="login.php" method="post">
<input type="text" name="user_email" />
<input type="password" name="user_password" />
<button></button>
</form>
Login.php
include 'config.php';
$email = mysqli_real_escape_string($con, $_POST['user_email']);
$password = mysqli_real_escape_string($con, $_POST['user_password']);
$query = "SELECT * FROM users WHERE user_email = '". $email ."' AND user_password = '". $password ."'" ;
$result = mysqli_query($con, $query);
if (mysqli_num_rows($result) == 1) {
$_SESSION['login_user'] = $username;
header('Location: dashboard.php');
} else {
echo 'fail!';
}
?>
header.php
<?php
session_start();
if( !isset($_SESSION['login_user']) ){
header('Location: index.php');
} else{
echo 'Logged in';
}
?>