i want to randomly display my banners at equal times per day

Discussion in 'PHP' started by adsegzy, Nov 21, 2010.

  1. #1
    Hello friends, am having some advert banners to this play on my site. i have written the script that will randomly select the banner, but the problem is that at the end of the day some banners are displayed more that others eg. at the end of a day, a banner might have been displayed 300 times while another will just be displayed 70 times. Pls what can i do to randomly select the banners but at the end of each day, all the banners will have been displayed at the number of time or the difference in the number of times displayed will not be much. code/syntax for this will be appreciated.

    regards
     
    adsegzy, Nov 21, 2010 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    It would help if we knew what your working with... but just off the cough if your using rand() try using mt_rand() instead as a better randomiser
     
    MyVodaFone, Nov 21, 2010 IP
  3. deepakg

    deepakg Peon

    Messages:
    48
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Might be this code give you some help to display banners at equal times per day

    <?PHP 
     
    /*  random(  $max  integer  ) 
          Returns  a  random  number  between  0  and  $max-1; 
    */ 
    FUNCTION  random(  $max  ) 
    { 
                    $x  =  RAND(); 
                    $y  =  GETRANDMAX(); 
     
                    $r  =  $x  /  $y  *  ($max  -1  ); 
     
                    $r  =  ROUND(  $r++  ); 
                    RETURN  $r; 
    } 
     
    /*  Read  the  directory,  add  all  "banner*"  files  with  to  the  array 
    */ 
    $i  =  0; 
    $d      =  DIR( "."); 
    whle($entry=$d->read()) 
                    IF  (SUBSTR($entry,0,6)  ==  "banner") 
                                    $array[$i++]  =  $entry; 
    $d->close(); 
     
     
    /*  pick  a  banner  at  random 
    */ 
    $r  =  random(  $i  ); 
     
    /*  Send  a  no-cache  header,  and  the  gif  type  header,  and  output  the  file. 
    */ 
    HEADER(  "Pragma:  no-cache"  ); 
    HEADER(  "Expires:  Monday  01-Jan-80  12:00:00  GMT"  ); 
    HEADER(  "Content-type:    image/gif"); 
    PASSTHRU(  "cat  $array[$r]"  ); 
     
    ?>
    Code (markup):
     
    deepakg, Nov 22, 2010 IP
  4. Grit.

    Grit. Well-Known Member

    Messages:
    1,424
    Likes Received:
    22
    Best Answers:
    1
    Trophy Points:
    110
    #4
    Have you considered adding a section that connects to a database? or writes to an external file, counting the impressions, and if impressions are more than the other banners, changing the banner, and updating the count. Then all you have to do is arrange to reset your counts each day (or specified time period)
     
    Grit., Nov 22, 2010 IP