I am trying to create a simple Ajax Login system and I have a jQuery Ajax call in my login.php as:
if(proceed){
var data = 'email='+tempEmail+'&pass='+tempPass;
var loginreq = $.ajax({
type: "POST",
url : "assets/tempusers.php",
cache: false,
data: data
});
loginreq.done(function(html) {
if(html=='true'){
window.location.replace('app.php');
}
else {
$("#loginRequest").before('<div class="alert alert-danger err" role="alert">Email or Password Is Not Correct</div>');
}
});
}
The tempusers.php File is like:
<?php
session_start();
include 'conconfig.php';
$con = new mysqli(DB_HOST,DB_USER,DB_PASS,DB_NAME);
$email = $_POST['email'];
$pass = $_POST['pass'];
$query = "SELECT * FROM tempusers WHERE user='$email' AND pass='$pass'";
$result = mysqli_query($con,$query)or die(mysqli_error());
$num_row = mysqli_num_rows($result);
$row=mysqli_fetch_assoc($result);
if( $num_row >=1 ) {
echo 'true';
$_SESSION['uName'] = $row['uName'];
}
else{
echo 'false';
}
?>
and in my app.php I have
<?php
session_start();
if(!empty($_SESSION['uName'])){
header('Location: login.php');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Secret Land</title>
</head>
<body>
<h1>Hi This is App</h1>
</body>
</html>
I am sure that I am inputting correct User Email ans Password into the boxes but the app.php is not showing up! I am not getting any error message either.
When I remove the beginning part of the app.php from the page every thing works fine!
<?php
session_start();
if(!empty($_SESSION['uName'])){
header('Location: login.php');
}
?>
Can you please let me know what i am doing wrong and what is causing this issue?