Click to See Complete Forum and Search --> : Random Link?


Jokersbay
04-20-2006, 06:09 PM
Is it piossible to get a random picture that is a link to show up? what is the code?

The Little Guy
04-20-2006, 06:53 PM
Place all the images in a folder and change the code below to go to that folder. At the very bottom of the script, you will see the "href", change the link to what you want.
<?php

/* Customise this line to change to your images folder */
$dir = 'images/homepage/';
$dh = opendir($dir);
/* The following loop scans the directory specified ignoring folders and Thumbs.db */
while (false !== ($filename = readdir($dh))) {
if($filename == "Thumbs.db" || is_dir($filename)){
}else{
$files[] = $filename;
}
}

/* Generate a random number */
$nooffildi = count($files);
$nooffiles = ($nooffildi-1);
srand((double)microtime()*1000000);
$randnum = rand(0,$nooffiles);

/* print the result */
echo "<a href="linkHere.html"><IMG SRC='$dir/$files[$randnum]' ALT='$files[$randnum]' BORDER='0'></a>";

?>

The Little Guy
04-20-2006, 06:55 PM
Or you can do a javascript random image:
http://www.javascript-page.com/ranimage.html

WebWisp
04-20-2006, 07:26 PM
Are you using multiple images to redirect to same site or are you looking for a link that will change with image?

Jokersbay
04-21-2006, 05:08 PM
1 image that will go to multiple sites, i have a games website and i need a random game image that people can click on to go to a random game

Thanks

ablaye
04-22-2006, 09:44 PM
I have a similar code written in ASP if you are interested.

HoboBen
04-30-2006, 02:17 PM
Or you can do server side include/shtml scripting...

Under the heading "Server Side Includes - SSI and SHTML"... (Click the box to expand it) http://www.tophatstuff.co.uk/public/portals/code.htm

Also, there is a javascript method on the same page under the heading "JavaScript Functions and Codes"