CodeIgniter Forums

Full Version: Correct Place to Set Global HTTP Headers?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to set the Strict-Transport-Security (HSTS) HTTP header for a site built using CodeIgniter, but because it's hosted using Google App Engine the only way to set the headers is in the application itself (you can only set custom headers for static content in the app.yaml configuration file).

What I'm wondering is, where would be the best place to put custom site-wide HTTP headers? I have a whole bunch of controllers so putting it in all of these isn't an option, and putting it in my header view doesn't seem like best practice (I also have a few variants, so I'd prefer not to have to edit them all).

Is there a good place to put custom HTTP headers that I want to appear in all responses from my site? My first thought was to create a helper and just use PHP's own header() function (as I don't think the Output class is available to global code in helpers?), but I'm curious if anyone can think of a better place to do this?
You could extend controllers through application/core/MY_Controller.php, set headers in MY_Controller __construct() then instead of extending CI_Controller, for controllers that need this new header, extend as MY_Controller.

Without knowing ins and outs of your project of course, that would be my first consideration, which may or may not be right for you (or anyone).