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: