Page 1 of 1
CSS using PHP
Posted: Tue Mar 23, 2004 9:56 pm
by waimichael
I always use the xxx.css.php for my CSS file that can include detect the browsers and OS, then use the suitable fonts and size. However, when I'm working in a new server recently, I can't use this technique. The Mozilla cannot run the xxx.css.php file, but can run the xxx.css. IE and Opera don't have this problem.
Would anyone tell me what the problem is and how to solve it? The server is using SUSE 8.0 with PHP 4.3.1 with Zend Optimizer V2.1.0 and MySQL 3.23.55.
Thanks.
Posted: Wed Mar 24, 2004 1:25 am
by compound_eye
sorry, this isn't an answer but a question,
i had exactly the same problem using IIS as a server, and I thought that it was netscape, not able to handle a css without the extesion *.css, not realizing it might be a server problem, so i ended up including all my styles in the head of the HTML document rather than linking to an external file,
so did mozilla work with a style sheet with a *.php extension on another server?
i wonder if there is anything in the way the
mime type for a style sheet is set up on the new server? ( this is not an expert suggestion just a co-confused wondering)
an alternative might be to have six or so static css files and just dynamically specify the correct sheet in your output depending on the font size you want the
Code: Select all
<?PHP
$styleSheet = 'style_'.$browser. '_'. $size. '.css';
?>...
...<!-- link rel="stylesheet" href="<?PHP echo $styleSheet; ?>" type="text/css" -->
Posted: Wed Mar 24, 2004 1:49 am
by waimichael
Thanks for your info compound_eye.
I don't think that Netscape can't handle the css without end in .css. In my personal website (the other web hosting company) it works well on IE, Netscape, Mozilla and Opera. So I think it should be the setting problem of PHP or Apache.
Would anyone have idea about it? Comments are welcome ~
Posted: Wed Mar 24, 2004 11:31 am
by werlop
could you modify httpd.conf for apahce to parse css files as php?
ie, you would have css, and you would enter php as normal, and put in any code that you needed.
i have never tried this, so I don't know if it would work. Just a thought.
Posted: Thu Mar 25, 2004 3:26 am
by waimichael
Thanks werlop. Would you also tell me about the configuration that I have to modify in httpd.conf? I'm not familiar as Apache and I am just a web programmer ...

Posted: Thu Mar 25, 2004 3:52 am
by waimichael
I tried to add the following code in the httpd.conf:
AddType text/css .php
and restart the Apache, however it doesn't work ...
Could anyone help me?
Thanks.
Posted: Thu Mar 25, 2004 8:28 am
by Nay
I believe .htaccess rather than httpd.conf? I've never used httpd.conf to add extensions. Just make a .htaccess file containing that line and drop it into the CSS directory.
-Nay
Posted: Thu Mar 25, 2004 10:22 am
by werlop
Nay wrote:
I believe .htaccess rather than httpd.conf? I've never used httpd.conf to add extensions. Just make a .htaccess file containing that line and drop it into the CSS directory.
-Nay
Hey, it's open to debate. I remember reading somewhere that .htaccess files should only be used where necessarry, instead configuration should be done in httpd.conf where possible, ever authentication.
Might be wrong though.
If your going to use htaccess, make sure you set AllowOverride to "All"
Posted: Thu Mar 25, 2004 9:22 pm
by waimichael
Thanks Nay and werlop.
However, it seems not working ... I have no idea about it and now I have to seperate two css file which one for Mozilla-based browsers and one for others.
I really don't know why my personal web hosting can do it ...

Posted: Thu Mar 25, 2004 9:32 pm
by McGruff
Stick with .css files and use a php script to pick one: return a file path and echo it in your page template.
Always best to keep a clean separation between different "things" - or you start running into problems such as this.
Posted: Fri Mar 26, 2004 12:12 am
by waimichael
Thanks McGruff for your suggestion.
One question is that now I have two set of CSS file: one is .css and other one is .css.php. If I modified one, I have to modify the other one. It's easy to make mistake and hard to maintain the codes. If I use the PHP script to pick one, that's mean I have to seperate several sets of CSS for each browser ... isn't it?
Posted: Fri Mar 26, 2004 8:20 am
by McGruff
Yes - one per format and another "parent" stylesheet.
The parent contains the main style info and is always defined. A 2nd sheet is chosen per format: this overides the main css here and there, as required.
Posted: Fri Mar 26, 2004 4:40 pm
by compound_eye
im still curious as to whether anyone could answer his original question, why netscape would be upset about a css file with the extension .php from one server but not another, what could be the diference in the behaviour of the servert hat would cause this?