Home Backend Development PHP Tutorial PHP newbies on the road (5)_PHP tutorial

PHP newbies on the road (5)_PHP tutorial

Jul 21, 2016 pm 04:00 PM
php one and interaction tool construction Features of Simple website software

Building a simple interactive website (1)

Many features of PHP are related to other software or tools. Using the PHP knowledge we have learned so far, we can try to build a simple interactive website. We can learn a lot through this process. Okay, let's now focus on the construction of a typical personal website.

5.1 Plan a website

Generally, a personal website includes a welcome page, a guestbook page, a bookmark link page, a counter, contact information, and even a photo collection and some music files etc.

5.2 Use include and require for modularization

We look at some websites built with PHP. Almost every page of the website has include and require embedded in the PHP file. This is because using include and require not only enhances the readability of the code, but also divides the site into modules for management. Generally speaking, there will definitely be duplicate content for every page on a website. For example: the navigation bar at the head of the page, advertising icons, or side navigation, etc. There may also be a copyright or some text-based navigation bar in the footer of each page, which is the bottom of the page. If we want to modify content such as the navigation bar or logo on a large website containing hundreds of pages, using our previous methods, we can only make changes to each page. Needless to say, everyone can imagine what an arduous and painful task this is. So, do we have a better solution? The answer is yes. We can put the repeated content into a file, and then use PHP's include and require functions to dynamically call the file on each page that requires this content. In this way, if we want to modify the reused content on all pages in the future, we only need to change the file containing the repeated content.

In order to make it easier for everyone to understand, let us first look at a simple application of include and require:

Start with an HTML page, maybe you will include it in the header of each page of the site ( head.htm).


My personal homepage



Page content (content.htm).


Welcome to my humble abode, although there is nothing here yet.



End of HTML page (trail.htm)



Use include and require The function separates HTML from PHP and divides HTML and PHP into modules:
/*
Call the head of the HTML page
*/
require("head.htm ");
/*
Call the content of the HTML page
*/
require("centent.htm");
/*
Call the tail of the 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, universal page headers and footers.

Title page--front.htm
Here we have a very simple html file:


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



My personal homepage


Welcome



What.



But I hope there will be more soon.






Copyright ? Myself, 1999





Contact information page--count.htm
Similarly we have another simple page:


<br>My personal homepage--contact information<br></TITLE> ; <br></HEAD> <br><BODY> <br><H1> <br>My personal homepage<br></H1> <br><H2> <br>Contact information <br></H2> <br><HR> <br><P> <br>You can contact me at 1-800-PHP-INFO<br></P> <br>< HR> <br><P ALIGN="CENTER"> <br><SMALL> <I> <br>Copyright ? Myself, 1999 <br></I> </SMALL> <br></P> <br></BODY> <br></HTML> <br><br><br>5.4 From HTML to PHP <br><br> From the above you can see that each Each page has the same header and footer.Writing the same information to each page like above is fine when the workload is light, but imagine how much effort you have to expend when there are more than 100 pages and you need to change their header or bottom for them all? What a tedious and boring task it is to manually change page after page! So we should write PHP header and bottom files for these pages, and then we just need to reference them in every HTML page. A file containing PHP code is included in both the include and require functions. Regardless of the file extension, it is treated as a PHP file. We will place these include files in a subdirectory called include and make them files with the .inc suffix. Below we will write the common content of these sites into the file. <br><br> Site-wide common variable settings: common.inc <br><? <br>// Site-wide common variable <br>$MyEmail = "phptalk@tnc.org"; <br>$MyEmailLink = "<a href="mailto:$MyEmail">$MyEmail</a>"; <br>$MyName = "PHP Talk"; <br>$MySiteName = $MyName."'s Home Page"; <br>?> <br><br>Universal page header: header.inc <br><? <br>// Define the universal page header <br>?> <br><HTML> <br><HEAD> <br><TITLE> <br><? echo "$MySiteName - $title"; ?> <br>











Universal page bottom: footer.inc
//Universal page bottom
?>




Copyright ? by

, 1999





New page front.php3:
include("include/common.inc");
$title = "Welcome";
include( "include/header.inc");
?>


Welcome to my humble abode, although there is nothing here yet.



But I hope there will be more soon.


include("include/footer.inc");
?>

New count.php3:
< ;?
include("include/common.inc");
$title = "Contact Information";
include("include/header.inc");
?>


You can contact me at 1-800-PHP-INFO


include("include/footer.inc");
?>

Now you can appreciate the benefits of this arrangement. If you want to change the header or bottom of the page, you only 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. It's also worth noting that you can include files with any file name or file extension into your file, and you can even include files from other sites.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/317011.htmlTechArticleBuilding a simple interactive website (1) Many features of PHP are related to other software or tools. Using the PHP knowledge we have learned so far, we can try to build a simple interaction...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1665
14
PHP Tutorial
1269
29
C# Tutorial
1249
24
How reliable is Binance Plaza? How reliable is Binance Plaza? May 07, 2025 pm 07:18 PM

Binance Square is a social media platform provided by Binance Exchange, aiming to provide users with a space to communicate and share information related to cryptocurrencies. This article will explore the functions, reliability and user experience of Binance Plaza in detail to help you better understand this platform.

Best Practices for Dependency Injection in PHP Best Practices for Dependency Injection in PHP May 08, 2025 am 12:21 AM

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

Best PHP Performance Optimization Techniques Best PHP Performance Optimization Techniques May 07, 2025 pm 03:05 PM

PHP performance optimization can be achieved through the following steps: 1) use require_once or include_once on the top of the script to reduce the number of file loads; 2) use preprocessing statements and batch processing to reduce the number of database queries; 3) configure OPcache for opcode cache; 4) enable and configure PHP-FPM optimization process management; 5) use CDN to distribute static resources; 6) use Xdebug or Blackfire for code performance analysis; 7) select efficient data structures such as arrays; 8) write modular code for optimization execution.

2025 Binance Binance Exchange Latest Login Portal 2025 Binance Binance Exchange Latest Login Portal May 07, 2025 pm 07:03 PM

As the world's leading cryptocurrency exchange, Binance is always committed to providing users with a safe and convenient trading experience. Over time, Binance has continuously optimized its platform features and user interface to meet the changing needs of users. In 2025, Binance launched a new login portal aimed at further improving the user experience.

The latest download tutorial for Ouyi OKX6.118.0 version The latest download tutorial for Ouyi OKX6.118.0 version May 07, 2025 pm 06:51 PM

The latest download tutorial for Ouyi OKX6.118.0 version: 1. Click on the quick link in the article; 2. Click on the download (if you are a web user, please register the information first). The latest Android version v6.118.0 optimizes some functions and experiences to make trading easier. Update the app now to experience a more extreme trading experience.

Top 10 digital virtual currency trading apps in 2025 Summary of the top 10 digital currency exchange apps Top 10 digital virtual currency trading apps in 2025 Summary of the top 10 digital currency exchange apps May 08, 2025 pm 05:24 PM

Ranking of the top ten digital virtual currency trading apps in 2025: 1. Binance: Leading the world, providing efficient transactions and a variety of financial products. 2. OKX: It is innovative and diverse, supporting a variety of transaction types. 3. Huobi: Stable and reliable, with high-quality service. 4. Coinbase: Be friendly for beginners and simple interface. 5. Kraken: The first choice for professional traders, with powerful tools. 6. Bitfinex: efficient trading, rich trading pairs. 7. Bittrex: Safety compliance, regulatory cooperation.

The latest entrance address of Binance Exchange in 2025 The latest entrance address of Binance Exchange in 2025 May 07, 2025 pm 07:00 PM

As the world's leading cryptocurrency exchange, Binance is always committed to providing users with a safe and convenient trading experience. Over time, Binance has continuously optimized its platform features and user interface to meet the changing needs of users. In 2025, Binance launched a new login portal aimed at further improving the user experience.

How to register in the ok exchange in China? ok trading platform registration and use guide for beginners in mainland China How to register in the ok exchange in China? ok trading platform registration and use guide for beginners in mainland China May 08, 2025 pm 10:51 PM

In the cryptocurrency market, choosing a reliable trading platform is crucial. As a world-renowned digital asset exchange, the OK trading platform has attracted a large number of novice users in mainland China. This guide will introduce in detail how to register and use it on the OK trading platform to help novice users get started quickly.

See all articles