Forum Moderators: not2easy

Message Too Old, No Replies

Using a dynamic page to serve CSS with PHP

         

AffiliateDreamer

4:24 pm on May 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi,

Is it perfectly acceptable to use a .php file to server CSS content?

The reason is I want to due some server side processing on the CSS stylesheet and there need to use a non .css file extension.

So i'll have something like:

<STYLE type=text/css media=screen>@import url( somefile.php?a=1 );
</STYLE>

MattyMoose

5:10 pm on May 30, 2005 (gmt 0)

10+ Year Member



If you're able to change your apache configurations, you can change the extension assoc. for PHP to include anything with .css. I think it would be parsed normally if there's no PHP tags in it.

AddType application/x-httpd-php .php .css

Should work.

MM

encyclo

5:21 pm on May 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It should work well if you take into account two aspects: the first is to make sure you explicitly define the mime type of the CSS file as
text/css
. The second is that you test to ensure that the file is cacheable - otherwise you risk it being called from the server every time, in which case you might as well have the CSS inline and save on server load.

There's a good thread in the CSS forum library which might be of interest:

  • Server Side Scripting in CSS Files - is it possible? [webmasterworld.com]
  •