| CSS Constants More examples |
There is no end to the usefulness of this approach. We can reuse cookie data or grab selector names from a database or a parsed document. We could allow an XML notation for the CSS and turn it into valid CSS on the fly.
An example of how to use parameters sent to the page could be to allow visitors to define a width of the content:
header('content-type:text/css');
header("Expires: ".gmdate("D, d M Y H:i:s", (time()+900)) . " GMT");
// grab the parameter w and set the variable w to its value
// if the parameter is not an integer, set w to 740
$w=preg_match('/(\D)/',$_GET['w'])?$w:$_GET['w'];
width:<?php echo $w;?>px;
background:<?php echo $blue;?>;
border-bottom:1px solid <?php echo $green;?>;
Or we can apply different color schemes according to the section:
header('content-type:text/css');
header("Expires: ".gmdate("D, d M Y H:i:s", (time()+900)) . " GMT");
$self=$_SERVER['PHP_SELF'];
if (preg_match('/aboutus/',$self))
else if (preg_match('/clients/',$self))
else if (preg_match('/downloads/',$self))
background:
<?php echo $colour1;?>;
border-bottom:1px solid
<?php echo $colour3;?>;
color:
<?php echo $colour2;?>;
Each of these examples requires the maintainer of the site to know about PHP, and may give her the chance to break it or add unsafe code. If we want to ensure that we have something like CSS constants with a less steep learning curve and less power to the maintainer, we can parse a CSS file with PHP. |
| Return to Listing |