Forum Moderators: coopster

Message Too Old, No Replies

Using css out of the database and not a css file?

         

benj0323

11:48 am on Nov 12, 2004 (gmt 0)

10+ Year Member



I have an issue and I would greatly appreciate any help you can offer me.

My website is template based, and all of the templates contents are stored in a database. Well my css code is stored in a template, which is in the database. Currently I am just echoing out the content by using a variable like $global_css. Well the downside to this is that I have to put all of the CSS in <style> tags, so it doesnt get cached. So inorder to cache the CSS I need to use a link tag instead of <style></style> tags. So the only way to use the link tag is to link to a css file. Well since all of my CSS is stored in the database I figured I would just echo out my css in a php file and then just link to that, but I have been unsuccessful. Basically my question is, why doesn't this work?

<link rel="stylesheet" type="text/css" href="echocss.php" media="all" />

When you go to echocss.php its the same exact thing as going to a css file. It has all of the css information in it. I even tried changing the type and it didnt work either:

<link rel="stylesheet" type="application/x-httpd-php" href="echocss.php" media="all" />

Does it have to be a .css file? Any ideas how I can do this using a php file?

Thanks for your help.

benihana

11:53 am on Nov 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



use .htaccess (assuming apache server) to parse .css files as php. then link to the css as normal.

benj0323

12:18 pm on Nov 12, 2004 (gmt 0)

10+ Year Member



Yep I just did that and it didn't seem to work. What did work was this though.

In the php file you have to set the mime type to

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

before you echo out the contents.

So that works now.