Alternately, you can use output buffering. At the very beginning of the file, before ANYTHING else, call this:
<?ob_start();?>
and then at the very end of the file, call this:
<?ob_end_flush();?>
With that code in place, you can start sessions or send headers from anywhere in the code.