I have created css page called style.php and included this the top:
<?php header('Content-type: text/css'); ?>
Does this make you cringe. Is it a terrible idea? I am doing this because I have created a CMS that allows the admin to control colors on pages (so the style.php script queries the database and grabs the hex values).
Any thoughts?
This is a fine solution, just make sure that you are serving up the appropriate headers. See my blogpost about a related topic (search for ‘The important headers are’ to get to the right section).
One more thing:
With the caching you might get into the situation where the user changes the color she wants to see, but (because it is cached at the client), the page doesn’t update. To invalidate the cache, append a ?=id at the end of the URL, where ID is a number that is stored for the user (for example in the session) and is incremented every time she changes the color scheme.
Example: