Skip to content

Using php for style sheets

March 11, 2013

Let’s say you don’t want your style sheets to be static, or to only change when you upload a new .css file. There is hope. One can set a .php file to be a style sheet and run the .php to do what it needs php-wise to get the style.

What needs to be done is to set the header  content type to text/css.

For example:


header('Content-type: text/css');
$colorpick = array("#fff", "#f0f", "#ff0", "#0ff", "#f33", "#33f", "#3f3");
$theone = rand(0, count($colorpick)-1);
body {
    background-color: <?php echo $colorpick[$theone]; ?> ;

Then I can include the php file as a css in the normal way:

<link href="compute-style.php" rel="stylesheet" type="text/css">

From → Technology

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: