【问题标题】:php Content-type: text/css not workingphp 内容类型:文本/css 不起作用
【发布时间】:2016-05-17 10:36:31
【问题描述】:

我有一个 style.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;
}
";

如果我打开 color.php,它会很好地打印颜色。但在页面中它不会覆盖 style.css #menu 红色。怎么了?有什么帮助吗?

谢谢朋友们!

【问题讨论】:

  • 你检查过$m的值来确认它不是空的吗?
  • @farooqaaa 如果我在浏览器中打开 color.php 它会显示 #menu{ background-color:blue; } 但在我的页面中它不是蓝色的......

标签: php mysqli


【解决方案1】:

尝试像这样更改第一行的顺序:

session_start();
include_once("mysqli.php");
header("Content-type: text/css");

内容类型可以被您包含的脚本(mysqli.php)覆盖。 此外,“session_start”应该始终是您在使用会话的 php 脚本中做的第一件事。 (我把 session_start() 放在第一位的原因)

【讨论】:

    【解决方案2】:

    【讨论】:

    • 它是铬!但很高兴知道,我会在 IE 中检查它!谢谢
    猜你喜欢
    • 2015-12-22
    • 1970-01-01
    • 2014-02-26
    • 2011-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-24
    • 1970-01-01
    相关资源
    最近更新 更多