A simple interactive Web site example-Simple banner dynamic replacement (vi)
9. Simple Banner Dynamic replacement
I do not know if you have found the major sites on the banner ads banner, each time we visit these sites, will see a different advertising icon, or if you refresh the page every time, these ads banner will constantly change the random replacement. To achieve this effect although the use of JavaScript can also be achieved (like the Tenkine station of the dynamic transformation of advertising banner is by invoking JavaScript to achieve), but if we use PHP, we can also combine the database to do a large amount of data, such as a daily problem such as the function. Crap, let's take a look at how PHP can be used to achieve banner dynamic replacement function.
Simple banner Dynamic replacement PHP file (BANNER.PHP3): ? Generate random numbers Srand (Double) microtime () *1000000); Take a number between 0 and 4 $randval = rand (0,5); Show results echo "<a href=//gophp.heha.net/index.html><img alt= into the PHP world border=0 src= $randval .gif></a>"; ?>
We can find that the implementation of the program is very simple: the main thing is to use the Srand initialization random number generator to generate random numbers, and then call the RAND function within the defined valid range to obtain one of the random values, and finally display $randval.gif each picture banner, that is 0.gif, 1. GIF, 2.gif, 3.gif, or 4.gif. For the sake of understanding, I list the syntax and instructions for the RAND function as follows: Rand Syntax: int rand ([int min], [int Max]); return value: Integer Types of functions: mathematical operations Description: This function is used to obtain random values. Without specifying the maximum and minimum range of random numbers, this function automatically takes a random number from 0 to Rand_max. If a parameter is specified for min and Max, a number is taken from the specified parameter. For example, Rand (38,49) obtains a random value from 38 to 49. Where the UNIX system contains the 49,WIN32 system does not contain 49. It is noteworthy that in order to maximize the random number of random numbers, it is best to use Srand () to set new random numbers each time before taking random numbers. In this example, the time factor is added when a new random number is produced with Srand (), and the random number is generated at a random rate of one out of 10,000 when executed.
9.1 We change the Head.inc file to apply this simple banner dynamic replacement function, but also for different advertising banner link to their corresponding URLs.
Of course, first we have to prepare the banner icon to replace the exchange, but also to our page header plus our own website logo (01dc.gif).
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.