While using header function sometimes you got the error like: 'Cannot add/modify header information – headers already sent by…'
To avoid such situation you can use output buffering or just make sure that nothing was sent to the client.
Remember also that
headers MUST be sent
before any output is started. There are no exceptions from this rule, in
fact you cannot even sent a blank line to the output, executing code