You Clever Peeps !!

Discussion in 'HTML & Website Design' started by geekazoid, Jun 30, 2006.

  1. #1
    Hey i have this script which rotates an object ( im using .html files ) every page load from a specfic folder. Is there any addition to the script i could add to make it randomly change Daily not ever Refresh ?

    This is the first php script

    <?php
    
    //opening the text file, if this line gives you error when compiling
    //the code then you need to chmod 755 your text file
    $fcontents = join ('', file ('http://www.geekazoid.co.uk/Random/Random-Arcade/banner.php'));
    
    //Spliting contents of file by looking for ~ mark between codes
    //and storing everything into an array.
    $s_con = split("~",$fcontents);
    
    //getting a random number which will be within the limit of the
    //contents of the file, means if 5 different banners/ads then the number
    //will be between 0-4 (total 5 )
    $banner_no = (rand(21)%(count($s_con)-1));
    
    //simple scho banner
    echo $s_con[$banner_no];
    
    
    ?>
    PHP:

    This is the second one, The banners php script

    <?php
    srand ((double) microtime( )*1000000);
    $numbanners = 21;
    $banner = rand(0,$numbanners);
    echo "<table align=center class=maincats bgcolor=#999999 width=120><tr><td>";
    include ("./banners/$banner.html");
    echo "</td></tr></table>";
    ?>
    PHP:
    Im not sure which one you would need to change so i just gave you both, thanx dudes
     
    geekazoid, Jun 30, 2006 IP
  2. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you had 30 banners you could just serve up a different one according to the day of the month. Thats the easiest way to do it.
     
    mad4, Jun 30, 2006 IP
  3. geekazoid

    geekazoid Peon

    Messages:
    208
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thats not what im looking for, Im looking to make a game of the day

    and i wish to have about 300 games on rotation each day
     
    geekazoid, Jun 30, 2006 IP
  4. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #4
    So you want it to change daily but with 300 games per day?
     
    mad4, Jun 30, 2006 IP
  5. geekazoid

    geekazoid Peon

    Messages:
    208
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    no i want it to change daily, and there to be 300 games on the server for it to rotate through per day.... So one game per day so technically theres enough for 300 days
     
    geekazoid, Jun 30, 2006 IP
  6. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You could assign each game in the database to a particular date and then just load up the game for that date.

    If you write a script to start today and loop through the days one by 1 until you reach 300 and update the DB as you go this will populate the DB for you.
     
    mad4, Jun 30, 2006 IP
  7. geekazoid

    geekazoid Peon

    Messages:
    208
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    thats not what im after, I appriciate your help but what im looking for is a change to the script i have supplied to rotate my files not on pageload but per 24 hours
     
    geekazoid, Jun 30, 2006 IP
  8. brian394

    brian394 Well-Known Member

    Messages:
    226
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    108
    #8
    If you want it to change daily and not every time the user refreshes you can't use the rand() function. That will give you a random banner each time which is not what you want. You have to use some variable that PHP is aware of that changes exactly once per day. And, in fact, there is such a variable. Well, not exactly a variable, but a way of expressing the current date :D . If you type...

    
    date("z");
    
    Code (markup):
    in PHP it will return the days of days that have passed in the current year. This will, of course, change every day. There is a way you can use this to your advantage to make a script that automatically shows a different banner each day. Here's how to do it...

    
    //First, create the $s_con array like you're normally doing...
    $s_con = split("~",$fcontents);
    
    //Next, create a number which is the size of your array plus the number of days in the current year...
    $num = count($s_con) + date("z");
    
    //Next, mod that number by the number of items in your array to find the right index...
    $num = $num % count($s_con);
    
    //Next, use that number...
    $banner_no = $num;
    
    // Test it...
    echo 'banner number is ' . $banner_no;
    
    Code (markup):
     
    brian394, Jul 1, 2006 IP
  9. geekazoid

    geekazoid Peon

    Messages:
    208
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Brilliant, Thanx for the script. Where do i put it ?
     
    geekazoid, Jul 2, 2006 IP