whenever you request a page from a server, that page is sent back to you (your browser), including a whole bunch of headers. For example, the headers can tell the browser that the page doesn't exist (a 404) or that a page has been moved to a new location, so the browser can immediately redirect, etc. etc.
With the header() function you can alter these headers somewhat. But, of course this requires that no output has been sent to the users browser yet. Because, any data sent to the user, will have to be accompanied by some headers.