(CSS)Randomly generating images..

Super-Supra

(Banned)
4,111
I've got a banner, and I've got around 5 images that I want to randomly load in that banners place. In other words, everytime you access that page, I want the banner to randomly load, out of the 5 banner's in a specific folder.

I'm a n00bie at CSS and have no idea how to do this.

Thanks.
 
I Dont Think You Can Do That In CSS.
i do know that you can do somthing similar to this in php though

PHP:
<?php
$File = 'stat.txt';

$Images[] = '/images/Banner1.gif';
$Images[] = '/images/Banner2.gif';
$Images[] = '/images/Banner3.gif';

$fp = fopen($File, 'r');
$Stat = fread($fp, filesize($File));
fclose($fp);

if($Stat >= count($Images)) $Stat = 0;




echo "<img src=\"$Images[$Stat]\">";
$Stat++;

$fp = fopen($File, 'w');
fwrite($fp, $Stat);
fclose($fp);



?>

also this is not my code, i found it while looking for stuff on php
 
Yeah, CSS can't do anything like that. CSS is used for styling HTML objects, nothing more, nothing less.

Like spock said, you can use PHP. You could use Javascript, but then if the user doesn't have Javascript enabled, your pretty much <word>ed. Paste the following wherever you want the image to be displayed:
PHP:
<?php

// Name your images 1.jpg, 2.jpg etc. 

// Change this to the total number of images in the folder
$total = "11";

// Change to the type of files to use eg. .jpg or .gif
$file_type = ".jpg";

// Change to the location of the folder containing the images
$image_folder = "images/random";

// You do not need to edit below this line

$start = "1";

$random = mt_rand($start, $total);

$image_name = $random . $file_type;

echo "<img src=\"$image_folder/$image_name\" alt=\"$image_name\" />";

?>

Alternatively, you could put all of the above into and external .php file and include it from your HTML. So, in your HTML you'd have:
PHP:
<?php include('blah/image.php') ?>

Where blah/image.php is, is the location of your external PHP script. I shouldn't have to walk you through how to set up the script, just read the comments in the PHP and you'll be fine. 👍
 
Back