Make sure that any work that involves headers (e.g., whatever it is your doing on lines 143, 144, 145, 146, etc.) is done before generating any output (e.g., whatever is being generated by line 97).
You can't send headers after you've started sending content.