Banner Rotator - No Repeats...?

Discussion in 'PHP' started by Magestry, Feb 3, 2009.

  1. #1
    Hey guys,

    Just wondering if any of you know a way of creating a banner rotator that has no repeats..? Well, its a number rotator in my case and the number represents the name of an image. Is there any way in which I can have one code 10 times on one page, the same code and for there to be no repeats. Like maybe at the top of the page can be all the variables and stuff and the repeated 10 times below an outcome... I am not extremely good at PHP, but I can edit easily, just not create.

    Any help would be greatly appreciated, even if what I need is not PHP.

    Thanks.
     
    Magestry, Feb 3, 2009 IP
  2. proxywhereabouts

    proxywhereabouts Notable Member

    Messages:
    4,027
    Likes Received:
    110
    Best Answers:
    0
    Trophy Points:
    200
    #2
    Even a paid one?
    OIOpublisher has the function to rotate banners and will not show same banner at one time.
     
    proxywhereabouts, Feb 3, 2009 IP
  3. Magestry

    Magestry Active Member

    Messages:
    822
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    80
    #3
    No, all I am looking for is the rotator, no ads, no purchases, no complicated script, just a simple rotator that does not repeat itself. Thank you for the suggestion though.
     
    Magestry, Feb 3, 2009 IP
  4. Acecool

    Acecool Peon

    Messages:
    267
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #4

    I can build you one, based off a card/deck idea I had... Draw from the deck, use next each time and dont repeat, when empty show nothing..

    Did you want admin panel to add/remove, or just in the script?

    What features would you like? Such as: Insert url, image, title and thats it - flash ads, etc..

    -Josh
     
    Acecool, Feb 3, 2009 IP
  5. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #5
    Probably the easiest way would be to fill a folder/directory full of files named after your banner names, then glob/unlink files as they're used.

    bannerator.php
    <?php
    
    // "banners" will be a folder full of "*.banner" files
    $banners = glob('banners/*.banner');
    
    // If the folder was empty, there will be no banner
    if(isset($banners[0]))
    {
    	$banner = $banners[floor(lcg_value() * count($banners))];
    	unlink($banner);
    	$banner = str_replace('.banner', '', $banner);
    	printf('<a href="./site?id=%1$s"><img src="./banner%1$s.png"/></a>', $banner);
    }
    
    ?>
    Code (markup):
    index.php
    <html>
    
    ...
    
    <?php include "bannerator.php"; ?>
    
    ...
    
    <?php include "bannerator.php" ?>
    Code (markup):
     
    joebert, Feb 4, 2009 IP
  6. Magestry

    Magestry Active Member

    Messages:
    822
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    80
    #6
    Thank you joebert, just one problem, I found out that it deletes the files once they are used, which is not too good...

    Is there any way to remove the 'unlink' bit but still not have any repeats?

    Thank you very much, and if you can help Acecool, that would be great!
     
    Magestry, Feb 4, 2009 IP
  7. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #7
    Its quiet complicated, you must keep the records in a txt file or other way in a db table
     
    crivion, Feb 4, 2009 IP
  8. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #8
    An alternative would be to rename the files to "xxx.used" and have a cron job running every X minutes that renames everything back to "xxx.banner" when it can't find any *.banner files.

    <?php
    
    // "banners" will be a folder full of "*.banner" files
    $banners = glob('banners/*.banner');
    
    // If the folder was empty, there will be no banner
    if(isset($banners[0]))
    {
    	$banner = $banners[floor(lcg_value() * count($banners))];
    	rename($banner, "$banner.used");
    	$banner = str_replace('.banner', '', $banner);
    	printf('<a href="./site?id=%1$s"><img src="./banner%1$s.png"/></a>', $banner);
    }
    
    ?>
    Code (markup):
    Then cron would execute something like this every X minutes depending on how fast your stock depletes.
    <?php
    
    $banners = glob('/path/to/banners/*.banner');
    if(empty($banners[0]))
    {
       foreach(glob('/path/to/banners/*.used') as $used)
       {
          rename($used, str_replace('.banner.used', '.banner', $used));
       }
    }
    
    ?>
    Code (markup):
    Or, that cron job could even just be the fail condition to the first block of code.
     
    joebert, Feb 4, 2009 IP
    Magestry likes this.
  9. Magestry

    Magestry Active Member

    Messages:
    822
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    80
    #9
    Thank you loads, it took a lot of changing and testing, but I got it to work, basically, when the page loads, the images show and then get named .used at end and then at the end of the page they are renamed .png again lol, thank you very much joe, +rep coming your way :)

    Thanks again everybody!
     
    Magestry, Feb 5, 2009 IP