The "redirection" is clearly in the header function. Have you verified that page exists: copy the entire URL into the browser address and click...you should not get a "page not found/404" error
If the flow of code does not get to the header function, that means PHP found an error in execution at an earlier point. It usually sends the error to standard output (to your browser in the HTTP response. What does that output say?
There are many points in your code where PHP execution errors are possible. You must not only resolve all PHP errors, but also warnings and notices...they are usually problems that should be errors.
is your HTTP request what it should be?? Did you set up a form (HTML form markup) with textbox elements that are named 'username' and 'password' that are transmitted with the click? Did you use the POST instead of GET method? The script wants POST.
is your MySQL database set up properly?
you have an include file: was it found?? using the require() function instead of include would given an error rather than perhaps a notice or warning.