we'll need to see some code, but basically a header must be sent before anything is sent to the browser (ie before any HTML is echoed out).
A common mistake is to use a location header low down in the script, forgetting that all PHP is executed on the loading of the page, and will therefore be ineffective at executing "on event" code. You'll need javascript for that if it is indeed the case.