CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Apache configuration (http://www.codingforums.com/forumdisplay.php?f=69)
-   -   PHP in CSS (http://www.codingforums.com/showthread.php?t=285983)

JAG 01-18-2013 04:49 AM

PHP in CSS
 
How can I use some PHP code in my CSS files?

In my .htaccess file, I tried:

AddType application/x-httpd-php .css

and

AddHandler application/x-httpd-php5 .css

But it didn't work. :-( What am I doing wrong?

epheterson 01-18-2013 06:30 AM

I don't understand the question.

CSS is generally a completely separate entity from PHP. If you'd like to actively modify CSS code, you should look into javascript solutions, and you can even use PHP before/after the javascript command.

Fou-Lu 01-18-2013 06:41 AM

Not a PHP issue.
Make sure you have AllowOverride set in httpd.conf to include FileInfo as well. If using the mod_mime.c and AddType isn't working, than checking the httpd.conf for the AllowOverride configurations is where to start.
You also don't really need to do it. Client developers could verify, but best I know browsers don't do any extension verification on an imported stylesheet. Assuming that's correct, you can successfully import a .php file without needing to add css to a parsable type.

Dormilich 01-18-2013 07:16 AM

Quote:

Originally Posted by Fou-Lu (Post 1307062)
Client developers could verify, but best I know browsers don't do any extension verification on an imported stylesheet. Assuming that's correct, you can successfully import a .php file without needing to add css to a parsable type.

yupp, browsers only care about the MIME type. i.e. as long as the MIME type is text/css the file extension doesn’t matter.

note: Apache automatically assigns text/html to PHP files, if not overwritten in the PHP script.

Fou-Lu 01-18-2013 03:32 PM

Yep, good to note the content type. That's easy to fix in PHP of course; simply add header('Content-type: text/css'); to the first instruction for PHP.

tracknut 01-18-2013 04:00 PM

You might also look into LESS CSS, depending on what you're needing. I find it a much cleaner way to manage macros and such in CSS than using PHP.

Dave


All times are GMT +1. The time now is 08:30 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.