我已经设置了一个背景更改脚本,它在我的其他一个网站上工作得很好,当我尝试在这个新网站(http://bit.ly/1Hwbn94)上这样做时,它只显示第一个背景图像并且确实不要每 20 秒随机更改一次(在单击另一个页面后)。
我是不是把 PHP 代码弄乱了?到目前为止我找不到错误。也许我必须向 header.php 添加一些内容?
random_img.php 中的 PHP 代码
<?php
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header('Content-Type: image/jpeg');
$bilder = glob( "../showcase/images/*.jpg" );
$seed = floor(time()/20);
srand($seed);
$random_image = $bilder[rand(0, count($result)-1)];
header('Location:'.$random_image.'');
?>
CSS代码
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
background: url("../random_img.php") no-repeat top left fixed; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; background-attachment: fixed;
}
最佳答案
在这一行 $result
是未定义的
$random_image = $bilder[rand(0, count($result)-1)];
正确
$random_image = $bilder[rand(0, count($bilder)-1)];
关于php - 随机图像背景更改 PHP CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29848600/