I'm looking for a script that will call a random image linked to its corresponding site on pageload. Anyone know a javascript or php way to do this?
+1
A:
<?php
$random = array(
array('image' => 'http://example.com/image1.jpg', 'url' => 'http://example1.com/'),
array('image' => 'http://example.com/image2.jpg', 'url' => 'http://example2.com/'),
array('image' => 'http://example.com/image3.jpg', 'url' => 'http://example3.com/'),
array('image' => 'http://example.com/image4.jpg', 'url' => 'http://example4.com/'),
);
$current = rand(0, count($random) - 1);
print "<a href=\"" . $random[$current]['url'] . "\"><img src=\"" . $random[$current]['image'] . "\" alt=\"\" /></a>\n";
?>
Quick and easy. Might not be the best way of doing it - I'd personally hook it into a database instead of a static array - but it'll have you up and running in seconds.
ceejayoz
2008-10-23 16:48:36