diff --git a/inc/infoutils.php b/inc/infoutils.php
index 32baa94507d786dc04cbf4bf1ed229d2a2ff9267..096662d2437b6126e70f97eb0387da128aa5cf4d 100644
--- a/inc/infoutils.php
+++ b/inc/infoutils.php
@@ -265,17 +265,15 @@ function msg($message,$lvl=0,$line='',$file=''){
 
     if($line || $file) $message.=' ['.basename($file).':'.$line.']';
 
-    if(!headers_sent()){
-        if(!isset($MSG)) $MSG = array();
-        $MSG[]=array('lvl' => $errors[$lvl], 'msg' => $message);
-    }else{
-        $MSG = array();
-        $MSG[]=array('lvl' => $errors[$lvl], 'msg' => $message);
+    if(!isset($MSG)) $MSG = array();
+    $MSG[]=array('lvl' => $errors[$lvl], 'msg' => $message);
+    if(headers_sent()){
         if(function_exists('html_msgarea')){
             html_msgarea();
         }else{
             print "ERROR($lvl) $message";
         }
+        unset($GLOBALS['MSG']);
     }
 }