This is my code for checking access.
$query = "SELECT user_table.status, expire FROM user_table WHERE username = ?";
if($stmt = $mysqli->prepare($query)){
$username = phpCAS::getAttribute('uid');
$stmt->bind_param('s', $username);
$stmt->execute();
$stmt->store_result();
$returned_amount = $stmt->num_rows;
if($returned_amount>1)
die("To many user names exists for you!");
else if(empty($returned_amount))
header("Location: /101/index.php?type=nouser");
$stmt->bind_result($status, $expire);
$stmt->fetch();
$stmt->free_result();
$stmt->close();
if($expire != '0000-00-00 00:00:00' && strtotime($expire) <= time())
header('Location: /101/index.php?type=expired');
$access = $status;
}else die("Failed to prepare!");
?>
However when $returned_amount == 0
.
it doesn't hit header("Location: /101/index.php?type=nouser");
If I change the code to the following, it fixes the problem, but I don't see why changing it would help.
if($returned_amount>1)
die("To many user names exists for you!");
else if(empty($returned_amount)){
header("Location: /101/index.php?type=nouser");
exit();
}
If I remove the exit();
, the header won't be executed.