我有一个风格.css:
<link href="/file.css" rel="stylesheet" type="text/css" property='stylesheet'/>
#menu{
background:red; //file.css content
}
之后是 php:
<link rel='stylesheet' type='text/css' href='/color.php' />
//color.php content:
header("Content-type: text/css", true);
include_once("mysqli.php");
session_start();
$userid=$_SESSION['id'];
$stmt = $mysqli_link->prepare("SELECT site FROM cores where user=? limit 1");
$stmt->bind_param('i', $userid);
$stmt->execute();
$stmt->bind_result($color);
$stmt->fetch();
$stmt->close();
if($color=="blue"){
$m="blue";
}
else if($color=="green"){
$m="green";
}
echo"
#menu{
background-color:$m;
}
";
如果我打开颜色.php它会很好地打印颜色。 但在页面中它不会被覆盖样式.css #menu
红色。怎么了?有什么帮助吗?
谢谢朋友们!
尝试像这样更改第一行的顺序:
session_start();
include_once("mysqli.php");
header("Content-type: text/css");
内容类型可以被您包含的脚本覆盖(mysqli.php)。此外,"session_start"应该始终是您在使用会话的 php 脚本中做的第一件事。(我把session_start()放在第一位的原因)
你使用的是IE吗?
如果是,请看这里 - 可能会有所帮助header("Content-type: text/css");在Firefox和Chrome中工作,但在Internet Explorer 9中它显示为"text/html"