You cannot issue Headers after the output is already sent.
echo '<script>alert("Incorrect PassCode");</script>';
header('Location: index.php'); // This wont work after your echo
That code Won’t work. You can change that to a JavaScript redirect
echo '<script>
alert("Incorrect PassCode");
location.href="https://stackoverflow.com/questions/24247149/index.php";
</script>';
According to PHP Manual
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.
0
solved PHP not echo-ing