You can’t send headers after there is already some output. If you wish to add content to display if the redirect fails, put the header and footer in the relevant code block:
//login code
//if redirect happens, code execution halts, so there is no need for an if else
get_header();
//error message
get_footer();