html - Reuse PHP image randomizer -
i wrote simple image randomizer on php picks random image list using rand() function. code works perfectly, , random image generated when include on html picture.
the problem comes when try include twice in same html. random image generated , displayed both times included it, same image. in other words, repeated random image on page.
an easy way solve copy randomizer.php, give new name, , include both images in html. reason don't want because final html have 25 pictures, , feel there should better way this. keep in mind cannot add php functions html, given files hosted in different servers, , html server not support php.
if know of better fix other creating 25 copies of randomizer.php file (or creating 25 different files include it), please let me know. appreciate input!!
thank very, much!!
here's snippet of code:
if (count($filelist) > 0) { { //do-while loop new random image until image has not been used yet in session $imagenumber = rand( 0 , ( count($filelist) - 1) ); //get random image filelist $iterations++; } while( !(empty($_session['img' . $imagenumber])) && iterations < 200); $_session['img' . $imagenumber] = true; //this image number has been displayed $_session['shown']++; //increments number of shown pictures in signature $img = $folder.$filelist[$imagenumber]; }
it may browser thinks same image , caching, try setting name of image (emit header content-disposition/filename iirc) and/or adding unique tag end of image name random string, ( e.g. image.jpg?e0.6613725793930488
)
Comments
Post a Comment