Announcement

Collapse
No announcement yet.

Random Banners? (Please Help!)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Random Banners? (Please Help!)

    Hey everyone,

    I see that there are a good group of guys here that know html/js/php, so I wanted to ask my question here.

    I have two banners for my vBulletin community. I would like to make it to where every time a new page loads on the site for the user, one banner is chosen at random. The two banners are in these paths:

    forum/images/green/ducknationfootball.jpg
    forum/images/green/ducknationbasketball.jpg

    Could anyone please tell me the coding that would allow me to do this? And I would hate to be picky, but I do not want a tutorial on how to do it. If anyone knows html/js/php well enough that they could give me a code and tell me where to put it and/or what to replace, I'd be most appreciative.

    Thanks.

  • #2
    Well, if you have a php server, you can save this as well... whatever you want to call it .php and stick it in a folder, and it will gather and randomly display an image in the folder.
    So it would be
    <img src="forum/images/green/random.php">
    or something similar :/

    PHP Code:
     <?php 

    if ($dir opendir(".")) 



         
    $list buildimagearray($dir); 

         
    displayrandomimage($list); 




    function 
    buildimagearray($dir



         while (
    false !== ($file readdir($dir))) 

         { 

              if (!
    is_dir($file) && getimagesize($file)) 

              { 

                   
    $list[] = $file

              } 

         } 

         return 
    $list




    // selection + image output


    function displayrandomimage($list



         
    srand ((double) microtime() * 10000000); 

         
    $sig array_rand ($list); 

     

         
    $size getimagesize ($list[$sig]); 

         
    $fp fopen($list[$sig], "rb"); 

     

         if (
    $size && $fp

         { 

              
    header("Content-type: {$size['mime']}"); 

              
    fpassthru($fp); 

              exit; 

         } 



    ?>
    [siggy]

    Comment


    • #3
      So where exactly should I put this? I'm a bit confused.

      Comment


      • #4
        Just save it as a plain text file with the php extension, put it in a directory with only the files you want randomized in it, and use it as your image
        [siggy]

        Comment


        • #5
          or if you're totally PHP illiterate like I am, you might want to use this javascript alternative --
          HTML Code:
           <html>
          <body>
          <script type="text/javascript">
          var r=Math.random()
          if (r>0.5) 
          {
          document.write("<a href='http://www.w3schools.com'>Learn Web Development!</a>")
          }
          else
          {
          document.write("<a href='http://www.refsnesdata.no'>Visit Refsnes Data!</a>")
          }
          </script>
          </body>
          </html>
          just put this code where you want your banner, and replace the current links with yours.

          Comment


          • #6
            For the code I had put, you don't need to be php literate in any way. You don't need to know how to do anything except save the file and upload it with the banners you want randomized...
            [siggy]

            Comment

            widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
            Working...
            X