Section 10 building a simple interactive website (6)

Source: Internet
Author: User
Build a simple interaction website (6) 9. simple banner dynamic replacement I wonder if you have found the header advertisement banner on each major site. 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 is used to achieve this effect

Build a simple interaction website(Sat.)

9.SimpleBannerDynamic replacement

I wonder if you have found any header ads on major sitesBannerEvery time we access these sites, we will see different ad icons, or if you refresh the page each time, these adsBannerIt will change randomly. To achieve this effectJavascriptYou can also (ImageDynamic advertisement change for Tianji websiteBannerBy callingJavascript), But if we usePHPWe can also combine the database for a large amount of data, such as a single question every day. Let's take a look at how to use it.PHPTo achieveBannerDynamic replacement function.

SimpleBannerDynamic replacementPHPFile (Banner. php3):
//Generate random number
Srand(Double)Microtime() * 1000000 );
//In0And4Take a number between them.
$Randval= Rand (0, 5 );
//Display result
Echo "href/// Gophp.heha.net/index.html>PhpWorldBorder = 0Src= $Randval.Gif> ";
?>

We can find that the implementation program is very simple: it is mainly used firstSrandThis initialization random number generator generates a random number and then callsRandThe function obtains a random value within the defined valid range.,Last display$Randval.gifImagesBanner, That is0. gif,1. gif,2. gif,3. gifOr4. gif. To facilitate your understanding, I willRandThe function syntax and related descriptions are listed as follows:
Rand
Syntax:IntRand ([IntMin], [IntMax]);
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 starts from0ToRAND_MAXTo obtain a random number. IfMinAndMaxFrom the specified parameters.INumber. For exampleRand (38,49)From38To49To obtain a random value. WhereUNIXSystem inclusion49,Win32System does not contain49. It is worth noting that in order to maximize the random rate of a random number, it is best to use it before getting a random number each time.Srand()To set a new random number. In this exampleSrand()When a random number is generated, a time factor is added. when executed, a random number is generated at a random rate of one in one thousandth.

9.1We changeHead. incFile to apply this simpleBannerDynamic replacement function, but also for different adsBannerLink to the corresponding URLs.

Of course, we must first prepareBannerAnd add your website logo (01DC.gif).

New header file (Header. inc):
//Define general page headers
?>


<? Echo "$ <SPAN class = SpellE> MySiteName </SPAN>-$ title";?>


Topmargin= 2>


Tr




Tr


Tr


<> Tr><> Tr><> Tr>
Rowspan= "3" width = "19%"> <Img Src= "Http://gophp.heha.net/test/images/01dc.gif" width = "140" height = "60"> Rowspan= "3" width = "29%">
//Obtain random seeds
Srand(Double)Microtime() * 1000000 );
//In0And4Take a number between them.
$Randval= Rand (0, 5 );
//Display result
Switch ($Randval)
{
Case "0 ";
Echo "href/// Gophp.heha.net/index.html> src= $Randval.gif> ";
Break;
Case "1 ";
Echo "href= // Personal.668.cc/haitang/index.htm> <ImgBorder = 0Src= $Randval.gif> ";
Break;
Case "2 ";
Echo "href/// Gophp.heha.net/index.html> src= $Randval.gif> ";
Break;
Case "3 ";
Echo "href/// Gophp.heha.net/index.html> src= $Randval.gif> ";
Break;
Case "4 ";
Echo "href= // Personal.668.cc/haitang/index.htm> <ImgBorder = 0Src= $Randval.gif> ";
Break;
}
?>

Href= "../Test/form. php3" class = "text">Automatic mail sending test

Href= "../Test/php/php1.php3" class = "text">Easy ad replacement

Href= "../Password. php3" class = "text">Simple Password verification instance



Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.