Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-18-2013, 04:49 AM   PM User | #1
JAG
New Coder

 
Join Date: Feb 2011
Posts: 51
Thanks: 17
Thanked 0 Times in 0 Posts
JAG is an unknown quantity at this point
Post 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?
JAG is offline   Reply With Quote
Old 01-18-2013, 06:30 AM   PM User | #2
epheterson
New Coder

 
Join Date: Nov 2007
Posts: 50
Thanks: 2
Thanked 0 Times in 0 Posts
epheterson is an unknown quantity at this point
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.
epheterson is offline   Reply With Quote
Old 01-18-2013, 06:41 AM   PM User | #3
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 01-18-2013, 07:16 AM   PM User | #4
Dormilich
Senior Coder

 
Dormilich's Avatar
 
Join Date: Jan 2010
Location: Behind the Wall
Posts: 2,881
Thanks: 9
Thanked 291 Times in 287 Posts
Dormilich is on a distinguished road
Quote:
Originally Posted by Fou-Lu View Post
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.
__________________
please post your code wrapped in [CODE] [/CODE] tags
Dormilich is offline   Reply With Quote
Old 01-18-2013, 03:32 PM   PM User | #5
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 01-18-2013, 04:00 PM   PM User | #6
tracknut
Regular Coder

 
Join Date: Aug 2006
Posts: 892
Thanks: 4
Thanked 206 Times in 205 Posts
tracknut is an unknown quantity at this point
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
tracknut is offline   Reply With Quote
Reply

Bookmarks

Tags
php in css htaccess

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:45 AM.


Advertisement
Log in to turn off these ads.