What is the best way to store css data inside database and call it similar to how a css file would be

Tags: php,mysql,css

Problem :

I am attempting to store css files inside database and call them in the most effective wa using PHP. I know I can include a style.php file and just do a query to get the data; however, not sure if that is the best way or not. I'd prefer to not have

#blah { }
#blah 2 { }

show up on every page. I am attempting to make this work similar to how a typical css file would work where it is just a link similar to the way it is below. I have read about people using html page:

<link rel="stylesheet" type="text/css" href="style.php" />

style.php page:

header("Content-Type: text/css");

however, have also seen that that doesn't work well with IE.

So does anyone have any recommendations on how I can do this in the best way for all browsers?

Solution :

I post my suggestion here as an answer.

Try adding an .htaccess file if you don't have one. Include the lines:

RewriteEngine on
RewriteBase /
RewriteRule ^style\.css$ style.php [T=application/x-httpd-php,L]

This would rewrite style.css to the server as style.php and treat it correctly as an executable script. Remember to keep the header so that the file returned is identical to a static css file. Also note that css'es stay in the browser cache so to actually reload the css you would either need to change cache settings in htaccess, change the filename or tell your visitors to manually reload the page.

    CSS Howto..

    how to show product info after image in bigger zoom levels

    how to create css gradients and shadow

    CSS How to erase the border from the image link?

    How to align with digits inside to the right, jQuery

    CSS , 3 three columns, how to make the middle liquid? [closed]

    Greasemonkey: How to do something when style=“display: none;” changes?

    How to apply css to id generated dynamically?

    How to manage z-index of navigation menu?

    How to cancel left or right rules with an !important tag?

    How do I use a different image for each JQuery UI Slider handle

    Heroku Not Showing SCSS Background Images

    How can I resize my iframe keeping the ratio?

    How to apply jQuery on css selector :before [duplicate]

    How to set an auto minimum width on column with css?

    How to add custom layout and css in a CakePHP application?

    How can I count HTML elements on a printed page using CSS?

    How do you mimic multi row horizontal scroll table behavior with CSS and Divs?

    How to remove an css style from a div ?

    How to include (referencing) CSS Javascript jQuery in master page and content (child) page

    How do you set the background color for a variable height page?

    How can I align multiple lists in the same row?

    How to style the div to triangle using CSS? [duplicate]

    How to align an image on css?

    How to make the page to fit screen width on mobile device?

    CSS - How to achieve a mixed effect of “float left” and “text-align: center”?

    How to define different css based on element changing number

    Bootstrap: Only Show Fixed Footer In Larger Screens?

    How can I add custom search box on page?

    Foundation CSS Framework, how to change triangle on accodion

    How to replicate this css media jquery using javascript to support IE