[PHP] advanced tutorial: server-side embedding (SSI) for reference and simple cases between multiple pages

Source: Internet
Author: User

Server-side embedding: Server Side Include (SSI) is used to create functions, headers, footers, or elements that can be reused on multiple pages.


PHP Include and require statements

In PHP, the file can be inserted into another PHP file before the server executes the PHP file.
The include and require statements are used to insert useful code into other files in the execution stream.
Include is very similar to require, except for the differences in error handling:
1. Require generates a fatal error (e_compile_error) and stops the script.
2. Include will only generate warning (e_warning), the script will continue

Therefore, if you want to continue the execution and output the results to the user, use include even if the included files are lost.

Otherwise, in the Framework, CMS (Content Management System), or complex PHP application programming, always use require to reference key files to the execution stream. This helps improve application security and integrity when a key file is accidentally lost.

The inclusion of files saves a lot of work. This means that you can create a standard header, footer, or menu file for all pages. Then, when the page header needs to be updated, you only need to update the page header containing files.
Syntax

include 'filename';

Or

require 'filename';

Basic instance

Suppose you have a standard page header file named "header. php ". To reference this header file on the page, use include/require:

Example 2

Suppose we have a standard menu file used on all pages:
"Menu. php ":

echo '<a href="/default.php">Home</a><a href="/tutorials.php">Tutorials</a><a href="/references.php">References</a><a href="/examples.php">Examples</a><a href="/about.php">About Us</a><a href="/contact.php">Contact Us</a>';

This menu file should be referenced on all pages of the website. This is a specific practice:

Example 3

Suppose we have a variable inclusion file ("vars. php "):

<?php$color='red';$car='BMW';?>

These variables can be used in the call file:

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.