Zend - The PHP Company




Graphics

Add Code


A Random Image with Link  

Type: code fragment
Added by: jasendorf
Entered: 30/06/2000
Last modified: 08/12/2006
Rating: **** (5 votes)
Views: 10715
Random Image with Link - good for "did you know" type of banner which point people to new areas of a website (at least that's why I made it...) **** This uses $level from my code for the link level determiner ****


<?PHP
/* *****************
Random Image with Link 2.01
jasendorf@lcounty.com
This uses $level from my code for 
the link level determiner
***************** */

function display_random_img($align)    
      {

      
//seed the random number generator
      
mt_srand((double)microtime()*1000000);
      
      
//get a random number
      
$rand_image mt_rand(1);
      
      
//  +++Array of URLs+++
      //Corresponding numbers will start with 0.
      //When adding images and directories
      //remember to increase mt_rand max number
      
      
$arr_numlinks = array(
          array(
'num' => '0' ,
            
'url' => 'hr/' ,
            
'alt' => 'did you know? Human Resources posts job listings for many of the Licking County positions which open up each year.  Click here to find out more!'
          
),
        array(
'num' => '1' ,
            
'url' => 'is/' ,
            
'alt' => 'did you know? The Information Systems Department coordinates dozens of servers for county operations.  Click here to find out more'
          
)
      );

      
//match random number with a URL and assign it a string value
      
$key $rand_image;
      
$rand_image_num $arr_numlinks[$key][num];
      
$link_url $arr_numlinks[$key][url];
      
$alt_tag $arr_numlinks[$key][alt];
      
      
//use number to create a image URL string
      //create directory /rotators in the images directory
      //name rotating images rotate[number].jpg
      
      
      
$rand_image_url "${levels}images/rotators/rotate${rand_image_num}.gif";
      
      
//figure out the image size (thanks jsalido)
      
$imgsize GetImageSize ("$rand_image_url");     
      
$img_w $imgsize[0];
      
$img_h $imgsize[1];

      
//echo the image and its URL
      
echo "<a href="${levels}${link_url}">";
      echo 
"<img src="$rand_image_url" align ="$align" border="0" ";
      echo 
"width="$img_w" heigth="$img_h" ";
      echo 
"alt="$alt_tag">";
      echo 
"</a>";
}

display_random_img('right');


Usage Example




Rate This Script





Search



This Category All Categories