Random Splash Pages
April 26, 2002 by daynah
Filed under Code Snippets, PHP
I was looking through my email and found this email from Grace:
Hi Daynah! It’s me, Grace. I would like to ask a question if you don’t mind -_-; Sorry if I am bothering you. I would like to ask if how can I make random splash pages with php? Or do you know any scripts I could download for
that? Thank you so much. And hope you are having a great week =)
Here is a piece of code that Albert (my boyfriend) wrote. It creates an array of random images to use. It’s pretty simple to modify if you want to create random splash pages. If you have comments/questions, please leave them below.
<?php
// Function name: randomimage($showimage)
// Purpose: Create an array with random data for an image
// Use: Please link http://php-princess.net/
function randomimage($showimage)
{
// ARRAY OF SPLASH IMAGES
$bgimages = array('images/splash1.jpg','images/splash2.jpg',
'images/splash3.jpg','images/splash4.jpg',
'images/splash1.jpg','images/splash2.jpg',
'images/splash3.jpg','images/splash4.jpg');
$bgtext = array ('Picture of Splash 1','Picture of Splash 2',
'Picture of Splash 3','Picture of Splash 4',
'Picture of Splash 1', 'Picture of Splash 2',
'Picture of Splash 3', 'Picture of Splash 4');
$bgmax = count($bgimages)-1;
// Check if viewing additional image option is
// set / look for non-integer value passing
if ((!isset($showimage)) || (!ereg ("^[0-9]{1,2}$", $showimage)))
{
srand((double)microtime()*1000000);
print_r($names);
srand ((double) microtime() * 10000000);
$rand_keys = array_rand ($bgimages, 2);
// obtain random image from array
$bgimage = $bgimages[$rand_keys[0]];
$bgalt = $bgtext[$rand_keys[0]];
$bgkey = $rand_keys[0];
}
return array($bgimage,$bgalt,$bgkey);
}
// Creates a list of the variables with random image
list($bgimage,$bgalt,$bgkey) = randomimage($showimage);
// Put printout into variable $mainbody
$mainbody = '
';
// Print out $mainbody
print "$mainbody";
?>
Related Products:
Code: The Hidden Language of Computer Hardware and SoftwareWhat do flashlights, the British invasion, black cats, and seesaws have to do with computers? In CODE, they show us the ingenious ways we manipulat... Read More >
PHP Solutions: Dynamic Web Design Made EasyThis is the second edition of David Power's highly-respected PHP Solutions: Dynamic Web Design Made Easy. This new edition has been updated by David ... Read More >
Clean Code: A Handbook of Agile Software CraftsmanshipEven bad code can function. But if code isn’t clean, it can bring a development organization to its knees. Every year, countless hours and significa... Read More >
Popularity: 19% [?]


@






