Need Help rotating a block of code

vistaland

Registered Member
Mar 1, 2008
61
118
I need to simple rotator script that can rotate thru 5-10 blocks of code.
Random is ok but would perfer one after the other, that change on each page load.

Can anyone point me in the right direction or recomend a existing script?
 
i am not going to write the script for you because its best to learn it hands on but i can help you on the way - the best method would be to use php and load the scripts randomly

check out both the "include()" and "rand()" statements for php - there are plenty of simple examples and tutorials online that will help you

at least demonstrate you've tried and ill help out some more if you cant figure it out

hth
 
you mean something like this?

PHP:
<?php $id = rand(1, 3); ?>

<?php if ($id==1) { ?>
ONE
<?php } ?>

<?php if ($id==2) { ?>
TWO
<?php } ?>

<?php if ($id==3) { ?>
THREE
<?php } ?>

hope this is helpful. if not just tell me. maybe i can help you
 
just do this...

<?php
$x=(rand(1,5));
$script="script$x.php";
include $script;
?>

say you have 5 scripts

save each of your scripts that you want to use in seperate files called script1.php script2.php etc

Explanation of code...

$x=(rand(1,5));
This line will create a random number between 1 and 5 ie 3

If you have more than 5 scripts increase the 5 to the number of scripts you have

$script="script$x.php";
This line creates the file name reference it basically inserts the random number into the file name ie script3.php

include $script;
this line tells the browser which file name to open ie include script3.php

place this code where you want to script to display/function

hope this makes sense...
 
Last edited:
Also take a look at PHP switch case statements, helps you get rid of never ending IF statements!!
 
Here's a couple php random rotation scripts. I know you wanted one that would rotate to the next one on page reload, but I think random would work just as good.

This one would rotate through 10 random php pages. You could include on these pages your affiliate links and banners, or modify the include to have it display your affiliate links directly.

Code:
// random number 1 - 10
$result_random = rand(1, 10);

if($result_random ==1){
echo ' ';
include("one.php");
}

if($result_random ==2){
echo ' ';
include("two.php");
}

if($result_random ==3){
echo ' ';
include("three.php");
}

if($result_random ==4){
echo ' ';
include("four.php");
}

if($result_random ==5){
echo ' ';
include("five.php");
}

if($result_random ==6){
echo ' ';
include("six.php");
}

if($result_random ==7){
echo ' ';
include("seven.php");
}

if($result_random ==8){
echo ' ';
include("eight.php");
}

if($result_random ==9){
echo ' ';
include("nine.php");
}

if($result_random ==10){
echo ' ';
include("ten.php");
}

?>

This one rotates a random affiliate link via a meta refresh:

Code:
<?php

$offers = array (
    "http://affiliateurl1.com",
    "http://affiliateurl2.com",
    "http://affiliateurl3.com",
    "http://affiliateurl4.com",
    "http://affiliateurl5.com"
);

$referer = $_SERVER['HTTP_REFERER'];
if($referer == "")
{
    $url = $offers[rand(-1, count($offers) + 1)];
    echo '<meta http-equiv="refresh" content="0;url='.$url.'">';
}
else
{
    echo '<meta http-equiv="refresh" content="0;url=http://yoursite.com">';
}

?>

and this one rotates a random banner and affiliate link depending on the seconds that the surfers computer shows. It's javascript though.

Code:
<SCRIPT LANGUAGE="JavaScript"> 
 
var dt = new Date(); 
var sec = dt.getSeconds(); 
 
// if (sec<=20) means seconds 0 through 20 
// change the IMG SRC = and the msg.link location to your own needs. 

if (sec<=10) { var msg="<IMG SRC=http://>"; document.write 
 
(msg.link("http://")) ;} 

else if (sec<=20) { var msg="<IMG SRC=http://>"; document.write 
 
(msg.link("http://")) ;}  
 
else if (sec<=30) { var msg="<IMG SRC=http://>"; document.write 
 
(msg.link("http://")) ;} 

else if (sec<=40) { var msg="<IMG SRC=http://>"; document.write 
 
(msg.link("http://")) ;} 

else if (sec<=50) { var msg="<IMG SRC=http://>"; document.write 
 
(msg.link("http://")) ;} 

else if (sec<=60) { var msg="<IMG SRC=http://>"; document.write 
 
(msg.link("http://")) ;} 


// the order of the if,else if, and else are important. The program reads from 
// the top down so if an if or else if work it will not read the following 
// else ifs or else. (else is a catch all). To add more you just add mores 
// else ifs and change the values. Say you wanted 6 images. 
// if (hr <=10) ....... 
// else if (hr <=20)........ 
// else if (so on until you reach 50) 
// else ...... 
// it's also easily modified for minutes months years if you want a banner 
// to appear all day on a certain day then then another on another day. 
<!-- end --> 
 
</SCRIPT>
 
Back
Top
AdBlock Detected

We get it, advertisements are annoying!

Sure, ad-blocking software does a great job at blocking ads, but it also blocks useful features and essential functions on BlackHatWorld and other forums. These functions are unrelated to ads, such as internal links and images. For the best site experience please disable your AdBlocker.

I've Disabled AdBlock