The cannot modify header content error is generated by anything printed to the screen before any header content.
header content would be things like Session() or header() commands.
when using functions that manipulate the headers, the beginning '<?' must be the VERY FIRST THING on the php script. if there is any whitespace above it, it will cause that error.
also, you can not 'echo' 'print' anything else to the page before the headers execute.
sometimes you may have all this under control, but a parse error or some other php error will print the error to the screen before your header scripts execute which then causes the header error.
hope this helps.