I am learning to use PHP for dynamic CSS. It looks pretty straightforward. So I created something very simple to test. Not being able to get it to work has been driving me nut for the whole day. Could someone tell me what I did wrong. Here are my simple codes:
- CSS file - dstyle.php. The first attribute is static just for checking if the file is actually loaded by the html page.
<?php
Header ("Content-type: text/css");
echo "
.font1 {color: #006600;}
.font2 {color: #$_GET[font2];}
";
?>
When I ran dstyle.php?font2=66666, a text file (.css) is generated like this:
.font1 {color: #006600;}
.font2 {color: #666666];}
Suggesting that thing is working in this regard.
- PHP web file - test_dstyle.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test dynamic css</title>
<link rel="stylesheet" type="text/css" href="dstyle.php" media="screen" />
</head>
<body>
<div class="font1">font1</div>
<div class="font2">font2</div>
</body>
</html>
When I ran test-dstyle.php?font2=666666, font1 shows correctly but not font2. One possible reason is that when the css file (dstyle.php) is loaded with "link" in the page header, the $GET[] variable doesn't get any value. If that is the case, what should I do? Or could this be due to other problems? I read many articles about dynamic css and php but no one mentions $GET[] issue. Any help shall be greately appreciated.
Paul