Bot-Factory 602 Posted November 21, 2014 Report Share Posted November 21, 2014 Hello. This question is not directly Ubot related. But maybe someone here has an idea how to do that. Challenge:I would like to use an URL like:www.mysite.com/picture.gif But everytime that URL is called, it will show a different picture. So basically a load balancer / rotator for pictures. I have seen a solution with a PHP script, but I can't use that because I can NOT use:www.mysite.com/picture.php I'm have to use .gif or .jpg in that URL. Creating a GIF from all the images is also NOT an option. So the backend server has to rotate the images automatically. Maybe the webserver or some kind of load balancer who does some URL rewriting? Any other ideas how to do this? Thanks in advance for your helpDan Quote Link to post Share on other sites
Pete 121 Posted November 21, 2014 Report Share Posted November 21, 2014 Could you use ssi or php include? Quote Link to post Share on other sites
Bot-Factory 602 Posted November 21, 2014 Author Report Share Posted November 21, 2014 Could you use ssi or php include? The only must have is that I have to use a URL with .gif or .jpg at the end. Everything else is possible. But I can not use a URL likewww.mysite.com/script.php Onwww.mysite.com/picture.jpgwww.mysite.com/picture.gif And the rest must be managed on the backend server. Dan Quote Link to post Share on other sites
Pete 121 Posted November 21, 2014 Report Share Posted November 21, 2014 This may do ithttp://bignosebird.com/recycle2.shtml or you could adapt this <li><a href="http://">zx</a><br />Some Text</li> <li><a href="http://">zx</a><br />Some Text</li> <li><a href="http://">zx</a><br />Some Text</li> add as many as you want... and a php file, I call mine ads.php <? $delim = "\n"; $cryfile = "random.txt"; $fp = fopen($cryfile, "r"); $contents = fread($fp, filesize($cryfile)); $cry_arr = explode($delim,$contents); fclose($fp); srand((double)microtime()*1000000); $cry_index = (rand(1, sizeof($cry_arr)) - 1); $herecry = $cry_arr[$cry_index]; echo $herecry . "\n"; ?> Quote Link to post Share on other sites
Bot-Factory 602 Posted November 21, 2014 Author Report Share Posted November 21, 2014 Only .GIF and .JPG are allowed in that URL. No .html .php .cgi A good use case would be posting a picture / banner to a forum. And I need a solution to show different pictures. And also redirect to different pages depending on which picture is shown when the user clicks that link. Dan Quote Link to post Share on other sites
UBotDev 276 Posted November 21, 2014 Report Share Posted November 21, 2014 Maybe try redirecting that image URL to PHP script and return image from there. Quote Link to post Share on other sites
Edward_2 85 Posted November 21, 2014 Report Share Posted November 21, 2014 Some javascript may work for you http://stackoverflow.com/questions/19693256/javascript-display-random-images https://www.google.ca/search?q=javascript+random+image Quote Link to post Share on other sites
HelloInsomnia 1103 Posted November 22, 2014 Report Share Posted November 22, 2014 I think this is possible via htaccess if I'm not mistaken, here is a Stack thread on it: http://stackoverflow.com/questions/12996453/htaccess-rewrite-serve-php-file-when-gif-is-accessed And this might help: http://www.generateit.net/mod-rewrite/index.php No promises on this but I think it's possible (I'm just not that experienced in htaccess) Quote Link to post Share on other sites
BobbyP 8 Posted November 23, 2014 Report Share Posted November 23, 2014 assuming every gif isa banner and has the link embedded and all images are ina folder called images.U ned a php script that rotates them random and a link to open a random gif. <?php ///////////////////////////////////////////////////////////////////// // This is the only portion of the code you may need to change. // Indicate the location of your images $root = ''; // use if specifying path from root //$root = $_SERVER['DOCUMENT_ROOT']; $path = 'images/'; // End of user modified section ///////////////////////////////////////////////////////////////////// function getImagesFromDir($path) { $images = array(); if ( $img_dir = @opendir($path) ) { while ( false !== ($img_file = readdir($img_dir)) ) { // checks for gif, jpg, png if ( preg_match("/(\.gif|\.jpg|\.png)$/", $img_file) ) { $images[] = $img_file; } } closedir($img_dir); } return $images; } function getRandomFromArray($ar) { mt_srand( (double)microtime() * 1000000 ); // php 4.2+ not needed $num = array_rand($ar); return $ar[$num]; } // Obtain list of images from directory $imgList = getImagesFromDir($root . $path); $img = getRandomFromArray($imgList); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>Demo</title> <style type="text/css"> body { font: 14px/1.3 verdana, arial, helvetica, sans-serif; } h1 { font-size:1.3em; } h2 { font-size:1.2em; } a:link { color:#33c; } a:visited { color:#339; } p { max-width: 60em; } /* so linked image won't have border */ a img { border:none; } </style> </head> <body> <h1>Display Random Image Using PHP</h1> <p><p>Each time the page is loaded an image will be selected at random. When you add more images to select from, you are less likely to get repeats from one page load to the next. </p></p> <a href="/"><img src="<?php echo $path . $img ?>" alt="" /></a> </body> </html> test this out to see if u get what u need. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.