Server-side include (small industry) used to create features, headers, footers, or content that will be reused for multiple pages.
Server-side Include
You can insert the contents of the file into the PHP file before the server executes it, with the include () or require () function. These two functions are the same in various ways, but how they handle errors. The Include () function generates a warning (but the script will continue to execute), and the () function needs to generate a fatal error (and the script will stop the error after execution).
These two functions are used to create features, headers, footers, or content that can be reused for multiple pages.
This can save the development of a considerable amount of time. This means that you can create a standard title or menu file that you want all of your pages, include. The head needs to be updated, you can only update an include file, or when you add a new page to your site, you may change the menu file (instead of updating all linked pages).
In the Include () function
All the text in the Include () function specifies the file and copies it to the file, include the use function.
Example 1
Suppose you have a standard header file called "header.php". Include header files on a page, using the Include () function, like this:
These three files, "default.php", "about.php" and "contact.php" should all include "menu.php" files. The following is the code "default.php":
<?php include ("menu.php");?>
Output.
Now let's look at the Require function www.111cn.net/
The Require () function is the same, include (), just a different processing error.
The Include () function generates a warning (but the script will continue to execute), and the () function needs to generate a fatal error (and the script will stop the error after execution).
If you add a file, include () function, and an error occurs, you may get an error message similar to the one below.
<?php
Include ("wrongfile.php");
echo "Hello world!";
?>
Warning: include (wrongfile.php) [function.include]:
failed to open stream:
No such file or directory in C:homewebsite est.php on line 5
Warning: include () [function.include]:
Failed opening ' wrongfile.php ' for inclusion
(include_path= ' .; C:php5pear ') in
c:homewebsite est.php on line 5
Www.111cn.net/phper/php.html
Hello world!
Please note that the echo of the statement is still executed! This is because the alert does not stop executing the script.
Now let's run the same example with the Require () function.
PHP Code:
<?php require ("wrongfile.php"), echo "Hello world!"; "
Hint:
p>
ning: require (wrongfile.php) [function.require]: failed to open stream:no such file or directory in C: Homewebsite est.php on line 5
Fatal Error: require () [function.require]: Failed opening Requir Ed ' wrongfile.php ' (include_path= '.; C:php5pear ') in C:homewebsite est.php on line 5
reprint: www.111cn.net/phper/php.html