I'm using a PHP/MySQL to style a web app using dynamic css (style.php).
The MySQL values are determined from the URL:
$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
if($url == "this") $style = "blue";
else( $style = "red"; )
The problem I seem to be having is that the style.php uses:
header('Content-type: text/css');
This causes $url to be equal to: "http://", also any other variables assigned outside of the style.php file are ignored.
Does anyone know how to get these $_SERVER (and other) variables to work?
Here is the full code
$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; // current URL
$key = true;
while($key){
mysql_select_db($database, $connection);
$query_rsTheme = "
SELECT s.name, s.url, t.name as theme, t.colour, t.hover
FROM db_site as s
INNER JOIN db_theme.theme as t ON t.name = s.theme
WHERE s.url = '$url'";
$rsTheme = mysql_query($query_rsTheme, $connection) or die(mysql_error());
$row_rsTheme = mysql_fetch_assoc($rsTheme);
$totalRows_rsTheme = mysql_num_rows($rsTheme);
if($totalRows_rsTheme == 1){ // sucessful match
$key = false;
$site = $row_rsTheme['name'];
$theme = $row_rsTheme['theme'];
$default_state = $row_rsTheme['colour'];
$hover_state = $row_rsTheme['hover'];
}
$tokens = explode('/', $url);
$remove = $tokens[sizeof($tokens)-2]."/";
$url = substr($url, 0, strpos($url, $remove));
}
header('Content-type: text/css');
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
$stylesheet = 'style.css';
$content = preg_replace('/\$([\w]+)/e','$0',@file_get_contents($stylesheet));
echo $content;
header()
function does not write anything in the$_SERVER
array. – Álvaro G. Vicario Aug 12 '13 at 8:40