I'm not even sure if this is possible with PHP but I am trying to create a dynamic css file and I'm having trouble finding a way to determine which page is loading the css file.
The problem comes in because the css file is loaded with the <link> tag so it's not "included" and technically it doesn't have a referer so I'm having a heck of a time trying to get this sucker to work.
Here's what I have tried within my css file:
if ($_SERVER["REQUEST_URI"] == "/index.php" || $_SERVER["REQUEST_URI"] == "/") {
echo "background-image: url(images/body.jpg);\n";
} else if ($_SERVER["PHP_SELF"] == "/index.php" || $_SERVER["PHP_SELF"] == "/") {
echo "background-image: url(images/body.jpg);\n";
} else if ($_SERVER["HTTP_REFERER"] == "/index.php" || $_SERVER["HTTP_REFERER"] == "/") {
echo "background-image: url(images/body.jpg);\n";
} else {
echo "background-image: url(images/body2.jpg);\n";
};
The real pain of this experiment is that I can't just echo out the server calls to see what the result is because it doesn't display in the page source because of the <link> tag. (Not to mention that if I load it directly it would give me different results.)
So is there a way to do this within the css file itself? I know I can do it in the call to the css file but I'd rather try to get this method to work if it is at all possible.