Prevent Redirect error after headers already sent

Prevent 'Error: Can't render headers after they are sent to the client.'