the headers already sent error doesnt mean there is more than 1 redirect, it menas ther is output between php tags.
at lin 160, there is a closing php tag, then a bunch of blank line till the next opening php tag at line 177:
?>
<?php
those blank lines are causing the error