0

I renamed my stylesheet as full.css.php and on the very beginning of the file i wrote this code:

<?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?>;
}

The browser is giving me this: Resource interpreted as Script but transferred with MIME type text/css: "http://localhost/root/_Viewer/css/full.css.php"..

And then error: "Uncaught SyntaxError: Unexpected token {" (this is the first brace from body css declaration).
If I look in source, I find that my file was sent as application/javascript file, not as text/css:

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

I know dynamic CSS won't be cached, but it's fine with me. It's more important now to have some settings easy to access. Need help to fix this.

Btw: I'm running this under XAMPP !

-i forgot to mention: i'm doing similar with one of my js files and it's working just fine ( header("Content-type: application/javascript"); )

derei
  • 193
  • 2
  • 4
  • 17
  • no need to use header just remove that line of header –  Aug 28 '13 at 13:14
  • 2
    Did you try to load it as `` instead of `script`? – Michał Prajsnar Aug 28 '13 at 13:18
  • then, how I will use PHP code inside my CSS file (to set variables) and also, the rendered content to be interpreted as css by the browser? - my alternative would be to force Apache to parse a .css file as php – derei Aug 28 '13 at 13:19
  • The answer i gave you in my previous comment works - checked myself. I'm not posting it as answer though, because i just found similar question, so i'll just give you the link: http://stackoverflow.com/questions/1445424/include-css-with-php-file-extension – Michał Prajsnar Aug 28 '13 at 13:25
  • @derei because it is a php file not a css file. The php sends headers of css. A JS file is no different than a CSS file they are both just text files that get sent to the client side to be handled on the client side. Whey would linking to the php file as a script be any different than linking to a php file by a style sheet? – Pitchinnate Aug 28 '13 at 13:44
  • Yeah, thanks ! I've checked too :D .The problem was that I had a function that automatically detected file extension and loaded it appropriately (all files were retrieved from an array). And so, my `full.css.php` was loaded as `php`. Of course, I forgot about it and I was blaming Apache for this. – derei Aug 28 '13 at 13:47

0 Answers0