you need to use
Code: 
ob_start();
at starting of script and

Code: 
ob_end_flush();
at the ending of script.