PHP newbies on the road (5)_PHP tutorial
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).
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:
My personal homepage--Welcome
My personal homepage
H1>
Welcome
What.
Welcome
But I hope there will be more soon.
Copyright ? Myself, 1999
Contact information page--count.htm
Similarly we have another simple page:
My personal homepage--contact information
My personal homepage
Contact information
You can contact me at 1-800-PHP-INFO
< HR>
Copyright ? Myself, 1999
5.4 From HTML to PHP
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.
Site-wide common variable settings: common.inc
// Site-wide common variable
$MyEmail = "phptalk@tnc.org";
$MyEmailLink = "$MyEmail";
$MyName = "PHP Talk";
$MySiteName = $MyName."'s Home Page";
?>
Universal page header: header.inc
// Define the universal page header
?>
echo "$MySiteName - $title"; ?>
echo "$MySiteName"; ?>
echo "$ title"; ?>
Universal page bottom: footer.inc
//Universal page bottom
?>
Copyright ? by
echo "$ MyName ($MyEmailLink)"; ?>
, 1999
HTML>
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.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

thinkphp6...

Based on market data and common evaluation criteria, this article lists the top ten formal Web3 trading platform APPs in 2025. The list covers well-known platforms such as Binance, OKX, Gate.io, Huobi (now known as HTX), Crypto.com, Coinbase, Kraken, Gemini, BitMEX and Bybit. These platforms have their own advantages in user scale, transaction volume, security, compliance, product innovation, etc. For example, Binance is known for its huge user base and rich product services, while Coinbase focuses on security and compliance. Choosing a suitable platform requires comprehensive consideration based on your own needs and risk tolerance.

This article recommends ten well-known virtual currency-related APP recommendation websites, including Binance Academy, OKX Learn, CoinGecko, CryptoSlate, CoinDesk, Investopedia, CoinMarketCap, Huobi University, Coinbase Learn and CryptoCompare. These websites not only provide information such as virtual currency market data, price trend analysis, etc., but also provide rich learning resources, including basic blockchain knowledge, trading strategies, and tutorials and reviews of various trading platform APPs, helping users better understand and make use of them

Digital currency rolling positions is an investment strategy that uses lending to amplify trading leverage to increase returns. This article explains the digital currency rolling process in detail, including key steps such as selecting trading platforms that support rolling (such as Binance, OKEx, gate.io, Huobi, Bybit, etc.), opening a leverage account, setting a leverage multiple, borrowing funds for trading, and real-time monitoring of the market and adjusting positions or adding margin to avoid liquidation. However, rolling position trading is extremely risky, and investors need to operate with caution and formulate complete risk management strategies. To learn more about digital currency rolling tips, please continue reading.

This article provides detailed exchange recommendations and introductory tutorials for beginners in the currency circle. Commonly used exchanges such as Coinbase, Binance, Kraken, Ouyi and Sesame Open Door are recommended, and the steps for registration, identity verification, security settings, recharge and trading are introduced. The article also emphasizes the importance of security awareness, risk control and continuous learning, aiming to help beginners enter the digital asset field safely and rationally.

This article lists the top ten well-known Web3 trading platforms, including Binance, OKX, Gate.io, Kraken, Bybit, Coinbase, KuCoin, Bitget, Gemini and Bitstamp. The article compares the characteristics of each platform in detail, such as the number of currencies, trading types (spot, futures, options, NFT, etc.), handling fees, security, compliance, user groups, etc., aiming to help investors choose the most suitable trading platform. Whether it is high-frequency traders, contract trading enthusiasts, or investors who focus on compliance and security, they can find reference information from it.

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

There are six free market viewing software websites: 1. Binance platform, suitable for digital asset investors; 2. OKX platform, providing rich market data; 3. Sesame Open Door (Gate.io) platform, suitable for users who trade in Gate.io; 4. TradingView, providing professional charting tools; 5. CoinMarketCap, covering a wide range of digital asset data; 6. CoinGecko, providing project fundamental evaluation. When choosing a platform, you need to consider investment objects, chart function requirements, data comprehensiveness and user experience.
