Php – How to include CSS in php

css, php

i want to include my css/stylesheet via php so that…

<link rel="stylesheet" href="http://www.mydomain.com/css/style.php">

so that i can than dynamicly change different stylesheets…. how can i do that

Best Solution

As long as you set your MIME type in style.php to CSS, you should be in business. Add this to the very top:

<?php Header ("Content-type: text/css; charset=utf-8");?> 

Another option if you're running on an Apache server is to tell it to check .css files for PHP. Add this to your .htaccess file to do this:

AddType application/x-httpd-php .css 

Then you could simply include a regular .css file:

<link rel="stylesheet" href="http://www.mydomain.com/css/style.css">