i am trying to redirect the user when the login details are correct, but my header function is not running, I have tested the if statement without the header function by echo something out and this worked, so im not sure why the header is not being executed. any help would be appreciated.
login php
<?php
session_start();
require '../includes/class/login.php';
$login = new login();
$username_error=' ';
$password_error=' ';
$result=' ';
if(isset($_POST['username']) && $_POST['username'] !== ""){
$username = $_POST['username'];
$username = trim($username);
$user_exists = $login->user_exists($username);
if ($user_exists) {
$username_error = 'correct username entered ';
} else {
$username_error = 'username not found';
}
}
if(isset($_POST['password']) && $_POST['password'] !== ""){
$password = $_POST['password'];
$password = trim($password);
$password_check = $login->password_check($username,$password);
if ($password_check) {
$password_error = 'correct password entered ';
} else {
$password_error = 'password not found';
}
}
if (isset($_POST['login'])&& $_POST['login'] !== "") {
$log = $login->check_login($username,$password);
if ($log) {
$login->redirect('home.php');
//$user_session = 'welcome'.' '.$_SESSION['username'];
} else {
// Registration Failed
$password_error='Wrong username or password';
}
}
$return_data=array('username'=> $username_error, 'password'=> $password_error ,'user_session'=>$_SESSION['username']);
header('Content-Type: application/json');
echo json_encode($return_data);
exit();
?>
login in class
public function redirect($url)
{
header("Location: $url");
}