Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: PHP in CSS

  1. #1
    JAG
    JAG is offline
    New Coder
    Join Date
    Feb 2011
    Posts
    63
    Thanks
    24
    Thanked 0 Times in 0 Posts

    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?

  • #2
    New Coder
    Join Date
    Nov 2007
    Posts
    50
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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.

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #4
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,342
    Thanks
    13
    Thanked 349 Times in 345 Posts
    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.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #6
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,300
    Thanks
    10
    Thanked 283 Times in 282 Posts
    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


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •