9. Simple banner dynamic replacement
I wonder if you have found the header advertisement banner on all major sites. Every time we visit these sites, we will see different advertisement icons, or if every time you refresh the page, the banner of these advertisements will change randomly. Although javascript can be used to achieve this effect (like the dynamic conversion advertisement banner of Tianji website is implemented by calling javascript), if we use PHP, we can also combine databases to provide functions with a large amount of data, such as one question per day. Let's take a look at how to use PHP to implement the dynamic replacement function of banner.
Simple banner dynamic replacement php file (banner. php3 ):
<?
// Generate a random number
Srand (double) microtime () * 1000000 );
// Obtain a number between 0 and 4.
$ Randval = rand (0, 5 );
// Display the result
Echo "<a href = // gophp.heha.net/index.html> </a> ";
?>
We can find that the implemented program is very simple: Program. To facilitate your understanding, I will list the syntax and related descriptions of the rand function as follows:
Rand
Syntax: int rand ([int min], [int max]);
Return value: integer
Function type: mathematical operation
Description: This function is used to obtain random values. If the maximum and minimum ranges of random numbers are not specified, this function automatically retrieves a random number from 0 to RAND_MAX. If the min and max parameters are specified, a number is obtained from the specified parameters. For example, rand () obtains a random value from 38 to 49. The UNIX system contains 49 and the Win32 system does not. It is worth noting that in order to maximize the random rate of a random number, it is best to use srand () to set a new random number each time before getting a random number. In this example, the time factor is added when srand () is used to generate a new random number. During execution, a random number is generated at a random rate of one thousandth.
9.1 we changed the head. inc file to apply the simple banner dynamic replacement function and link different advertisement banner to their corresponding URLs.
).
New header file (header. inc ):
<?
// Define the general page header
?>
<HTML>
<HEAD>
<TITLE> <? Echo "$ MySiteName-$ title";?> </TITLE>
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.