Long answer: using a bit of black magic you can add variables to your CSS Files by asking Apache to redirect any stylesheet to a special PHP script which will open the stylesheet, find and replace any user-defined variables, then serve up the parsed content will be displayed as pure CSS.
<?php
$domain = "mywebsite1";
?>
// then elsewhere, building up some html/JS output
$('#dvBackGround').css('background','path/to/image/<?php echo $domain; ?>.jpg');
// back on with the page
You cloud create additional file called custom.css and place it in a folder relative to your PHP $domain var path. Inside it, you can put your CSS and always be sure what path to use in url(), like in background CSS property.
<?php
$domain = $_REQUEST['domain']; // Add validation to make sure someone doesn't redirect their to their own domain
header('Content-Type: text/css;');
?>
body{font-size:12px; background:url(<?php echo $domain; ?>/images/bg.gif) repeat-x;}
I am curious to know why you want a $domain variable at the top of every page?
I envisage "file not found " problems will arise when the files are uploaded to www.your-online-site.com.
The way I get round this is to test and see if platform is localhost and to define relevant constants.
I would think so long as you return a mime type header of text/css the browser will render it as a CSS instruction.
I used the above method for developing but unfortunately www.validation.w3.org does not recognise the .php extension.
To get round this I view the source using the FireFox browser then click on the stylesheet.PHP file and the source appears in another window. Source then copied, pasted and saved to stylesheet.css
I did not know that. That is good information to have. I’m sure there are ways that can be worked around it (if need be), but it is something to keep in mind that you will have to do a workaround to validate your stylesheets.