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></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. If you do not specify 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, a time factor is added to generate a new random number using Srand (), and a random number is generated at one out of 10,000 random rate when executed.
9.1 We change the Head.inc file to apply this simple banner dynamic replacement function, but also to the 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).
New header file (header.inc):
?
Define common page headers
?>
<HTML>
<HEAD>
<TITLE>;? echo "$MySiteName-$title";?> </TITLE>
<style type= "Text/css" >
<!--
. text {font-family: "Song body"; font-size:12pt color: #006633; Text-decoration:none}
-->
</style>
</HEAD>
<body topmargin=2>
<table width= "100%" border= "0" >
<tr>
<TD rowspan= "3" width= "19%" ></td>"
<TD rowspan= "3" width= "29%" >
?
Get the seeds of chaos
Srand (Double) microtime () *1000000);
Take a number between 0 and 4
$randval = rand (0,5);
Show results
Switch ($randval)
{
Case "0";
echo "<a href=//gophp.heha.net/index.html></a>";
Break
Case "1";
echo "<a href=//personal.668.cc/haitang/index.htm></a>";
Break
Case "2";
echo "<a href=//gophp.heha.net/index.html></a>";
Break
Case "3";
echo "<a href=//gophp.heha.net/index.html></a>";
Break
Case "4";
echo "<a href=//personal.668.cc/haitang/index.htm></a>";
Break
}
?>
</td>
<TD width= "52%" >
<div align= "center" ><a href= ". /test/form.php3 "class=" text > Automatically send a message test </a></div>
</td>
</tr>
<tr>
<TD width= "52%" >
<div align= "center" ><a href= ". /test/php/php1.php3 "class=" text "> Simple recurrent advertising replacement </a></div>
</td>
</tr>
<tr>
<TD width= "52%" >
<div align= "center" ><a href= ". /password/password.php3 "class=" text > Simple password validation instance </a></div>
</td>
</tr>
</table>
</body>
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.