Novice Road Video php Novice Road (v)

Source: Internet
Author: User
Building a simple interactive website (i)
Many of the features of PHP are related to other software or tools. Using the PHP knowledge we've learned so far, we can try to build a Web site that's simple to interact with. Using this process we can learn a lot of things. Well, we are now starting to focus on the construction of a typical personal website.
5.1 Planning a site
Generally a personal site includes a welcome page, a message page, a bookmark link page, a counter, contact information, and even a photo collection and some music files and so on.
5.2 Modular with include and require
We look at some of the PHP architecture of the site, almost every page of the website PHP file will have include and require embedded in the meantime. This is because the use of include and require not only enhances the readability of the code, but also divides the site into modules for management. In general, there must be duplicate content for each page on a Web site. For example: the navigation bar on the head of the page, the ad icon, or the side navigation. There may also be a copyright or some text-based navigation bar at the bottom of each page, which is the footer of the page. If we want to modify a navigation bar or logo on a large website that contains hundreds of thousands of pages, we can only make changes to each page in our previous methods. Needless to say, you can imagine what a difficult and painful errand this is. So, do we have a better solution? The answer is yes. We can put the duplicate content in a file, and then dynamically invoke the file with the PHP include and require functions on each page that needs the content. This way, if we want to make changes to these reusable content on all pages later, we just need to change the files that contain the duplicates.
To make it easy for everyone to understand, let's take a look at a simple application of include and require:
HTML page starts, maybe you will include it in the head of each page of the site (head.htm).


<title>My personal homepage</title>


Page content (content.htm).


Welcome to my humble abode, though there is nothing here for the time being.


End of HTML page (trail.htm)


Use the include and require functions to separate HTML from PHP and divide the HTML and PHP into modules:
/*
Call the header of the HTML page
*/
Require ("head.htm");
/*
Invoking the contents of an HTML page
*/
Require ("centent.htm");
/*
Call the end of an HTML page
*/
Require ("trail.htm");
?>
5.3 Let's start with a title page, a contact information page, and a resume page. We also need standard, generic page headers and bottoms.
Title Page--front.htm
Here we have a very simple HTML file:


<title><br> My personal homepage--Welcome <br></title>



My personal homepage



Welcome




Welcome to my humble abode, though there is nothing here for the time being.



But I hope I can get up more soon.





Copyright? Myself, 1999




Contact Information page--count.htm
Again, we have a simple page:


<title><br> My personal Homepage--Contact information <br></title>



My personal homepage



Contact information




You can contact me through 1-800-php-info.





Copyright? Myself, 1999




5.4 From HTML to PHP
From the above you can see that each page has the same head and bottom. Each page, like the one above, writes the same amount of information when the work is low, but imagine how much effort you spend when you have more than 100 pages and you need to change the head or bottom of all of them. What a tedious thing it is to make a page-by-page manual change! So we should write the PHP header and the bottom file for these pages, and then we just have to refer to them in each HTML page. The Include and require functions contain a PHP code file that, regardless of the file's extension, is considered to be a PHP file. We will place these include files in a subdirectory called include and take the file with. Inc as the suffix. Below we will write the common content of these sites into the file.
Total Station general variable setting: Common.inc
Total Station General variables
$MyEmail = "phptalk@tnc.org";
$MyEmailLink = "$MyEmail";
$MyName = "PHP talk";
$MySiteName = $MyName. "' S Home page ";
?>
General Page Header: Header.inc
Defining a common page header
?>


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









General Page Bottom: Footer.inc
General Page Bottom
?>



Copyright? By

, 1999




New Page FRONT.PHP3:
Include ("Include/common.inc");
$title = "Welcome";
Include ("Include/header.inc");
?>


Welcome to my humble abode, though there is nothing here for the time being.



But I hope I can get up more soon.


Include ("Include/footer.inc");
?>
The new count.php3:
Include ("Include/common.inc");
$title = "Contact information";
Include ("Include/header.inc");
?>


You can contact me through 1-800-php-info.


Include ("Include/footer.inc");
?>
Now you can appreciate the benefits of this arrangement. If you want to change the head or bottom of the page, you just need to change the corresponding file. If you want to change your e-mail address or even your name, just modify the Common.inc file on the line. It is also worth noting that you can include any file name or file extension in your file, you can even include files on other sites.

The above introduces the novice on the road video PHP Novice on the road (v), including the Novice on the road video content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    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.