February 19, 2009 – 10:22 am
var personId = <?php echo $_GET['id'] ?>;
I’m also going to start naming css files as “something.css.php” – so they, too, will be parsed by the php interpreter. I haven’t investigated the possibilities it opens up yet, but it would allow me to use variables in the CSS file and it would make it possible to set something (e.g., a colour) in one place, at the top of the file, which can recur wherever it’s needed (using php ‘echo’ statements). This would mean i’d only have to change it once and changes would be propagated throughout the file.
However, i had a bit of struggle to get that to work with Firefox 3. It works fine in IE7, Safari and Opera – and i was puzzled about why it didn’t work in Firefox as well. After a bit of experimenting, i realised that apache sends a “Content-type: text/css” header if the filename suffix is “.css”, but a text/html content-type header if it’s “php”. Obviously the other browsers don’t worry about that – but Firefox does. So, to make .css.php files work (if you’re using apache), you have to put the following line at the top of the file:
<?php header( 'Content-type: text/css' ); ?>
Note: this must be the very first line in the file. If there’s anything else before it – even a blank line – it won’t work, because once apache has sent anything to the browser it can’t send another header.