At the moment this code is simply picking a random background image from the array and setting it for each new page I navigate. I want a unique background image for each page refresh or each time I click to a new page without the same image being repeated until the array is empty. Currently the array is being reset each time I refresh/navigate and I am seeing some repeated backgrounds before all images in the array have been ‘used’. The array should reset only after all 7 backgrounds have been uniquely sampled. The location of my code is up the top of my ‘head’ html file which is being used across all pages using php ‘includes’. I’m thinking I must need to use a session but Im not sure. Any help please?
[code]<?php
$backgrounds = $background_history = array(‘one.jpg’, ‘two.jpg’, ‘three.jpg’, ‘four.jpg’, ‘five.jpg’, ‘six.jpg’, ‘seven.jpg’);
$result = “”;
for ($i = 1; $i < 8; $i++) {
if (empty($background_history)) {
$background_history = $backgrounds;
}
$key = array_rand($background_history, 1);
$selected = $background_history[$key];
unset($background_history[$key]);
$result = $selected;
}
?>
<style>
.all-backgrounds {
background: linear-gradient(rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0.45)), url(../static/backgrounds/<?php echo $result ?>) no-repeat center center;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
-o-background-size: cover;
height: 100%;
}
</style>
[/code]