Dynamic CSS with Apache and PHP
Friday, January 25th, 2008This is a little trick I came up with that helps me with dynamic CSS using Apache web server and PHP.
Basically, in the Apache settings, I added
AddType application/x-httpd-php .css
This code will pass CSS files to the PHP parser.
I stopped here, and everything’s great and dandy. So, I start to develop my website. I’m a no warnings/error whore, so when I see them, I like to fix them right away or it’ll just bug me.
So, while testing I viewed the javascript console in Mozilla. And I saw a lot of these…
I start thinking about this, and I figured that since CSS files are passed to the PHP parser in Apache, the MIME type is text/html.
So, to fix this, all I did in each CSS file, I added this
<?php header(’Content-type: text/css’); ?>
Basically, it just changes the MIME type so the browser will know what to do with it.
Now, I have no errors/warnings and CSS are dynamic.
If you know of another trick, I would like to hear it.