3RingStudios » V5

Professional Web Design, Best Flash Movies, Affordable Hosting, SEO Firm

[ HOME  ]      [ add to favoritesBOOKMARK  ]      [ print this pagePRINT  ]      [ email this pageEMAIL  ]
   
Sat Feb 11 2012 - 04:11 AM
"Everyone wants to go to heaven - but no-one wants to die to get there..." - Domino Harvey
 

How to Create Random Header Images in PHP


OK, so like, I was stuck there wanting to make my new website look even cooler, so I thought, …wouldn’t it be neat if I could have random background images in my header. That way, whenever someone revisits or refreshes or visits and new page - VIOLA! - a new header image. Cool, eh? But then I thought - “I’ll have to use PHP to generate a random number or numbers, and thus generate random images…

Here’s how I did it:

  1. Create a series of images that are all the same size that you want to be your random images. Name them all the same except for an incrementing number just before the filename suffix (.gif, .jpg) - eg: imagename1.jpg, imagename2.jpg, imagename3.jpg, etc…
  2. Upload them to your chosen image folder
  3. Wherever you want you random images to appear (I used a div tag to create random background images for my header area), place your variation of the code below:
    
    <div id='header' style='
    <?php
    srand ((double)
    microtime( )*1000000);
    $random_number
    = rand(1,3);
    echo ('background:
    url(yourimage'.
    $random_number.'.jpg)
    top no-repeat;');
    ?>
    '>
    <div id='content'>
    Content here.
    </div>
    </div>
    
  4. The bit of code that says “rand(1,3);” denotes the choice of random numbers between 1 and 3. Change this to your requirements - eg: If you need numbers between 5 and 15 - change it to: “rand(5,15);
  5. Call all your friends and tell them what a genius you are and that they should check out your cool new randomized images…

Hope that made someone’s day…


Leave a Reply

You must be logged in to post a comment.

Thank you.


NEED HELP FINDING SOMETHING?
Google


COPYRIGHTS AND CREDITS


COPYRIGHTS
All content on this web site Copyright © 2006 3RingStudios Inc. All rights reserved.

CREDITS
All articles and/or comments made on this web site falling under the Creative Commons License shown below may be used in full or in part for content on your web site or blog, providing that the terms of the Creative Commons License shown below (link) are met and that credit is given to our site using the following content and format:
About The Author
Paul Marek is Founder and General Go-To Guy at 3RingStudios.com, a Toronto, Canada based internet services firm offering advanced Web Design, Flash, and Search Engine Marketing services.

Creative Commons Licence
This work is licensed under a Creative Commons Licence.



LEARN MORE
button

 

Warning: include() [function.include]: URL file-access is disabled in the server configuration in /u/3/3rs/www.3ringstudios.com/V5/wp-content/themes/3ringstudios-inc/footer.php on line 6

Warning: include(http://www.3ringstudios.com/V5/goog_topad.php) [function.include]: failed to open stream: no suitable wrapper could be found in /u/3/3rs/www.3ringstudios.com/V5/wp-content/themes/3ringstudios-inc/footer.php on line 6

Warning: include() [function.include]: Failed opening 'http://www.3ringstudios.com/V5/goog_topad.php' for inclusion (include_path='.:') in /u/3/3rs/www.3ringstudios.com/V5/wp-content/themes/3ringstudios-inc/footer.php on line 6




Bluehost.com Web Hosting $6.95




WANT YOUR AD HERE? TELL US.



[ BACK TO TOP ]

This site is not affiliated with or sponsored by Google, Macromedia or Adobe.
® Google, ® Adwords and ® Adsense are registered trademarks of ® Google Corporation.
® Flash is a registered trademarks of Macromedia Inc. ® PhotoShop is a registered trademarks of Adobe Inc.
They are used here for identification and/or entertainment purposes only.

This website is powered by WordPress.
Entries and comments feeds. Valid XHTML and CSS.