hello guys can any one give me a Random Link Scripts
I Need Random Link Script
Collapse
X
-
This function returns a random file from a given folder. It also allows extension filtering.
Get a random row from a table. Useful for just about anything where you need a random entry. Put in anything you want, but just leave \"ORDER BY RAND()\" and \"LIMIT n\" where they are. (LIMIT can be set to any number you want though.) [/B][/B]PHP Code:function RandomFile($folder='', $extensions='.*'){ // fix path: $folder = trim($folder); $folder = ($folder == '') ? './' : $folder; // check folder: if (!is_dir($folder)){ die('invalid folder given!'); } // create files array $files = array(); // open directory if ($dir = @opendir($folder)){ // go trough all files: while($file = readdir($dir)){ if (!preg_match('/^.+$/', $file) and preg_match('/.('.$extensions.')$/', $file)){ // feed the array: $files[] = $file; } } // close directory closedir($dir); } else { die('Could not open the folder "'.$folder.'"'); } if (count($files) == 0){ die('No files where found :-('); } // seed random function: mt_srand((double)microtime()*1000000); // get an random index: $rand = mt_rand(0, count($files)-1); // check again: if (!isset($files[$rand])){ die('Array index was not found!'); } // return the random file: return $folder . $files[$rand]; }
SELECT * FROM `sometable` WHERE 1 ORDER BY RAND() LIMIT 1;
This will show a random link when someone comes to your page.
//set the urls
$urls = array("http://google.com" ,"http://hotmail.com" ,"http://hawkee.com" );
//set the text links
$text = array("Google" ,"Hotmail" ,"Hawkee");
srand(time());
//set the number in (rand()%3); for however many links there are
$random = (rand()%3);
echo ("<a href = \"$urls[$random]\">$text[$random]</a>");
Or see attach:
Comment



Comment