Proper use of headers in php
Posted on 2011-09-27
Headers seem to always give me trouble. There seems to be the rule that they must be the first code to get executed on the page, but I always run into trouble when I need to use multiple headers or different headers based on the outcome of an if/else. The project I'm working on specifically is an excel export of a database but the client doesn't want to have to login. So I have to at least put a noindex/nofollow robot on the page. When I add the doctype, <html>, <head>, <body> tags to put the robot in I get the error with the headers not being at the top. This rule seems to be enforced at times and not at others. There must be something I'm not seeing that triggers it.
My question is (all though maybe broad) what is the proper use of headers? or if anything how to get around this rule or what alternatives there are to headers.