header() only fails IF THERE IS OUTPUT TO THE PAGE BEFORE THE CALL TO HEADER().
www.php.net/header
You if statement will work fine as long as there is not output to the browser before it.
You have to remember that header() is not actually redirecting the person. It is sending them a text string that says to go somewher eelse, it is always up to the person's browser or user-agent whether or not to follow that instruction.
An option may be to just unset all variables that are set, or if you want to turn to the dark site, a Javascript redirect.
HTML meta-redirects may work as well.