我正在尝试制作动态CSS(使用php标头),但我在客户端有问题

时间:2013-08-28 13:12:48

标签: php xampp dynamic-css

我将样式表重命名为full.css.php,并在文件的最开头编写了此代码:

<?php
    header("Content-type: text/css; charset: UTF-8");

   //here I want to set all my css variables
   $font_color = '#ccf';

?>
//here starts the css
body{
    color: <?php echo $font_color?>;
}

浏览器给我这个:Resource interpreted as Script but transferred with MIME type text/css: "http://localhost/root/_Viewer/css/full.css.php".

然后错误:“Uncaught SyntaxError:Unexpected token {”(这是来自body css声明的第一个大括号)。
如果我查看源代码,我发现我的文件是application/javascript文件,而不是text/css

<script type='application/javascript' src='_Viewer/css/full.css.php'></script>

我知道动态CSS不会被缓存,但对我来说没关系。现在更容易让一些设置易于访问。 需要帮助来解决这个问题。

顺便说一下:我在 XAMPP 下运行

-i忘了提一下:我和我的一个js文件做的很相似,而且工作正常(header("Content-type: application/javascript");

0 个答案:

没有答案