混合饼干和 css 与 php
Mixing cookies and css with php
所以我有一个非常简单的 css 文件,它是根据使用 php 获取的 cookie 生成的。整个 css 也使用 php 显示,所以它
<?php header("Content-type: text/css");
$rand = $_COOKIE['randTopic'];
echo '
body {
margin-top: 50px;
margin-bottom: 50px;
background: none;
}
.full {
background: url("http://loremflickr.com/1920/1080/' . $rand . '") no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
';
?>
Loremflickr 只是一个服务,它给我随机的 flickr 图片,我也可以选择我实际正在做的主题。所以输出 css 看起来完全像这样:
body {
margin-top: 50px;
margin-bottom: 50px;
background: none;
}
.full {
background: url("http://loremflickr.com/1920/1080/wall
") no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
如您所见,有一个我并不想要的换行符,不知道为什么会出现在这里。我认为这可能会导致问题,您怎么看?
提前感谢您的帮助。
trim()
输出中的变量 -
echo '
....
background: url("http://loremflickr.com/1920/1080/' . trim($rand) . '") no-repeat center center fixed;
....
';
快速修复是对来自 cookie 的数据使用 trim()
函数。
但首先我会检查为什么会有换行符。检查您的代码。
所以我有一个非常简单的 css 文件,它是根据使用 php 获取的 cookie 生成的。整个 css 也使用 php 显示,所以它
<?php header("Content-type: text/css");
$rand = $_COOKIE['randTopic'];
echo '
body {
margin-top: 50px;
margin-bottom: 50px;
background: none;
}
.full {
background: url("http://loremflickr.com/1920/1080/' . $rand . '") no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
';
?>
Loremflickr 只是一个服务,它给我随机的 flickr 图片,我也可以选择我实际正在做的主题。所以输出 css 看起来完全像这样:
body {
margin-top: 50px;
margin-bottom: 50px;
background: none;
}
.full {
background: url("http://loremflickr.com/1920/1080/wall
") no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
如您所见,有一个我并不想要的换行符,不知道为什么会出现在这里。我认为这可能会导致问题,您怎么看?
提前感谢您的帮助。
trim()
输出中的变量 -
echo '
....
background: url("http://loremflickr.com/1920/1080/' . trim($rand) . '") no-repeat center center fixed;
....
';
快速修复是对来自 cookie 的数据使用 trim()
函数。
但首先我会检查为什么会有换行符。检查您的代码。