Highly Irregular
Highly Irregular

Reputation: 40519

Chrome and IE not recognising dynamic PHP CSS stylesheet

In the head of my html page I have:

<link media="screen" href="tabs.css.php?tabs=374,375,376,377,378,379,381,380" type="text/css" rel="stylesheet">

The CSS is dynamically created based on the tabs parameter.

This works in IE9, but not in Chrome or Firefox. However, when I tried saving the generated CSS as "tabs.css" and pointing Chrome to that, it worked. That doesn't help me much though because I need the style to be dynamically generated.

How can I get Firefox and Chrome to recognise the stylesheet?

Upvotes: 0

Views: 319

Answers (1)

Highly Irregular
Highly Irregular

Reputation: 40519

I fixed this issue by adding this line to the top (before any output is sent, even a blank line) of my PHP file which generates the stylesheet:

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

It seems that when the file has a .css extension it is correctly recognised by Firefox and Chrome as CSS, but not when it's got a .php extension. This other answer has some links that might be useful to you if you want to learn more.

Upvotes: 2

Related Questions