As far as I know you definetely need to turn on output buffering. Once you use it on your page, you can redirect easily within the page by checking the header and discarding it if necessary:
if (ob_get_length() != false)
{
ob_clean();
}
header ("Location: mypage.php4?var1=".urlencode($var1)."&var2=$var2&".SID);
exit;
Thorsten