vendredi 24 avril 2015

Random image background change PHP CSS

I have set up a background changing script, which works just fine on one of my other web sites and when I have tried to do it on this new one (http://bit.ly/1Hwbn94), it just shows the first background image and does not randomly change it every 20 seconds (after clicking on another page).

Did I mess something up with the PHP code? I cannot find the error up to now. Maybe I have to add something to the header.php?

PHP code in random_img.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 code

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;
}




Aucun commentaire:

Enregistrer un commentaire