a few days ago, I posted a question asking how to display random images. But actually, I need somthing that displays a random html document, not a random image. I have taken images, inserted them into an html doc and added hotspots to turn them into ads.html
Place the following code precisely where you want your included document to be rotated: <? $files = glob($_SERVER['DOCUMENT_ROOT'].'/html_inc/*'); include $files[array_rand($files)]; ?> Code (markup): Change html_inc to the name of the folder into which your random documents will be stored. Make sure the page is named .php, or that .html is set to be parsed as php by the server. And that's it. Just put your documents into that folder, and the server will serve up a random one every time! (Credit goes to Sea Otter for this gem).
function randInt(min,max) { var div = (max - min) + 1 var randNum = Math.random() for (var i = 0; i <= div - 1; i++) { if (randNum >= i / div && randNum < (i+1) / div) {return i + min} } } var abc = randInt(1,5); if (abc == 1) { document.write("<\"Your 1. HTML-Banner-Code\">"); } if (abc == 2) { document.write("<\"Your 2. HTML-Banner-Code\">"); } if (abc == 3) { document.write("<\"Your 3. HTML-Banner-Code\">"); } if (abc == 4) { document.write("<\"Your 4. HTML-Banner-Code\">"); } if (abc == 5) { document.write("<\"Your 5. HTML-Banner-Code\">"); } Activating code: <script language="JavaScript" type="text/javascript" src="rotation-script.js">
Why do it with JavaScript when you can do it much more cleanly with PHP, plus you don't lose search engines and people browsing without JS enabled?