You can create a regular PHP file starting with a CSS header:
<?php
header('Content-type: text/css');
After that, you can just echo out the CSS content. One way to do that is with heredoc syntax with a template system. The template puts variable values within '%%' percentage symbols as delimiters. Here's an example:
$css = <<<EOTAAA
* {
margin: 0;
padding: 0;
}
body {
background-color: %bg_color%;
background-image: url(images/bg.gif);
background-repeat: repeat-x;
font: 14px Arial, Helvetica, sans-serif;
}
div.my_div{
color: red;
width: %width%;
}
EOTAAA;
$search = array('%bg_color%', '%width%');
$width = width_function();//some function for determining width
$bg_color = bg_function();//some function for determining background color
$replace = array($bg_color, $width);
echo str_replace($search, $replace, $css);
Download Link:
In your HTML, create a link something like this with the URL of the file that will handle the request:
<a href="HTTP://www.example.com/download.php">Get CSS</a>
And then in your PHP file, change the header information to the following:
header("Content-Disposition: attachment; filename=\"custom.css\"");
header('Content-type: text/css');
header("Content-Type: application/force-download");
header("Connection: close");