Processing .css files as php?

I need to include some php code in my .css files (trying to avoid unnecessary hacks to account for browser inconsistencies). How do I tell the server to process .css files as php?


AddType application/x-httpd-php .css

Putting that in the .htaccess file would probably do the trick, but that’s probably not the best way to do it. I never tried it, so I don’t know if it would cause any problems or not.

Why not just put PHP code in your header that does what you want it to do, then includes the right .css file based on the results?

You could also look into CSS conditional statements. A Google search should bring up a bunch of tutorials.

:stuck_out_tongue: Save up to $96 at Dreamhost with ALMOST97 promo code (I get $1).
Or save $97 with THEFULL97.

Thanks for your help. Unfortunately, I actually knew that part. Perhaps a better way for me to have phrased my question would be:

Is there a way to change the site-wide configuration of PHP? .htaccess files work, but they have significant performance penalties, so I prefer to avoid them if at all possible.

Sorry my first question was kind of unclear, I posted it at something like 3am, so I wasn’t at the top of my game right then…

Dynamic stylesheets in PHP or any CGI script are easy. You just need to send the right value for the content-type header. No messing around with server configuration necessary.

HTML document:

And then in style.php:

<?php Header('Content-Type: text/css') ?> body { color: black; background-color: white; }
:cool: [color=#6600CC]Atropos[/color] |

That would be the logical thing to do, and it is what I have done as I’ve been developing my sites design. Now I’m ready to start actually developing a template for zen-cart, and I’m completely baffled by its completely uncommented php code. I’m far from a PHP guru, but I’m competent at it, but for the life of me, I’ve been unable to figure out how their file loading mechanism works. I make the changes to the code, and it just doesn’t seem to find the files.

But regardless, it would actually be slightly prefereable to make the change. This way, I can go back & add some php to my older css files without haveing to edit each file that loads them. Given a choice, that would be the preferred solution.

I see what you mean, as they scan a directory for CSS files by extension.

So rename all the CSS files from filename.css to filename.php and add the call to Header()

Then modify /includes/templates/template_default/common/html_header.php

Search for the calls to get_template_dir and get_template_part.

For get_template_dir, change the value of ‘.css’ to ‘.php’

For get_template_part, the last parameter should be ‘php’ instead of ‘css’

Works for me.

:cool: [color=#6600CC]Atropos[/color] |

I had tried that yesterday, but I guess my brain wasn’t at 100% when I tried to get this working at about 2am or so last night. When I had a chance to try it again after a good night sleep, I was able to get it working.