potresti provare a mettere

ob_start();

prima dello switch

e poi


ob_end_flush();

alla riga sotto la header location