PHP Novice (10) _php Tutorial

Source: Internet
Author: User
Tags types of functions
Building a simple interactive website (vi)

9. Simple Banner Dynamic replacement

I do not know if you have found the major sites on the header ad banner, every time we visit these sites, we will see different advertising icons, or if you refresh the page each time, these ads banner will continue to randomly replace the transformation. To achieve this effect although JavaScript can also be achieved (like Yesky station dynamic Transformation Advertising banner is done by invoking JavaScript), but if we use PHP, we can also be combined with a database to do a large amount of data, such as the daily problem of the function. Crap, let's take a look at how to use PHP to implement 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 "";
?>

We can find that the implementation of the program is very simple: mainly by using the Srand initialization random number generator to generate a random number, and then call the RAND function in the definition of the valid range to get one of the random values, and finally show $randval.gif each picture banner, namely 0.gif, 1. GIF, 2.gif, 3.gif, or 4.gif. To make it easy for everyone to understand, I have listed the following syntax and instructions for the RAND function:
Rand
Syntax: int rand ([int min], [int Max]);
return value: Integer
Types of functions: mathematical operations
Description: This function is used to obtain a random value. 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 of min and Max is specified, 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 worth noting that in order to make the random number the most random rate, it is best to use Srand () to set a new random number before each random number is taken. In this example, the time factor is added when using Srand () to generate a new random number, and the random number is generated at random rate of one out of 10,000 at execution time.

9.1 We changed the Head.inc file to apply the simple banner dynamic replacement feature, and also to link to their corresponding URLs for different ad banner.

Of course, first we have to prepare the banner icon to replace the exchange, and also to add our own website logo (01dc.gif) to our page header.

New header file (header.inc):
Defining a common page header
?>


<title><? echo "$MySiteName-$title";?></title>
















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 "";
Break
Case "1";
echo "";
Break
Case "2";
echo "";
Break
Case "3";
echo "";
Break
Case "4";
echo "";
Break
}
?>

Automatically send mail test

Simple Recurrent advertisement Replacement

Simple Password Verification Example





http://www.bkjia.com/PHPjc/316989.html www.bkjia.com true http://www.bkjia.com/PHPjc/316989.html techarticle Building a simple interactive website (vi) 9. Simple banner Dynamic Replacement I do not know if you have found the major sites on the header ads banner, every time we visit these sites, will see not ...

  • 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.