English
German

PHP Include

Server Side Includes SSI

You can insert the content of one PHP file into another PHP file before the server executes it, with the include() or require() function.

The two functions are identical in every way, except how they handle errors:

    * include() generates a warning, but the script will continue execution
    * require() generates a fatal error, and the script will stop

These two functions are used to create functions, headers, footers, or elements that will be reused on multiple pages.

Server side includes saves a lot of work. This means that you can create a standard header, footer, or menu file for all your web pages. When the header needs to be updated, you can only update the include file, or when you add a new page to your site, you can simply change the menu file (instead of updating the links on all your web pages).


PHP include Function

The include() function takes all the content in a specified file and includes it in the current file.

If an error occurs, the include() function generates a warning, but the script will continue execution.
Example 1

Assume that you have a standard header file, called "header.php". To include the header file in a page, use the include() function:

Example:

<html>
<body>

<?php include("header.php"); ?>
<h1>Welcome to my home page!</h1>
<p>Some text.</p>

</body>
</html>


PHP require Function

The require() function is identical to include(), except that it handles errors differently.

If an error occurs, the include() function generates a warning, but the script will continue execution. The require() generates a fatal error, and the script will stop.
Error Example include() Function

Example:

<html>
<body>

<?php
include("wrongFile.php");
echo "Hello World!";
?>

</body>
</html>


PHP Tutorial,PHP Include, PHP Include example, learn PHP Include,explain example PHP Include online free training PHP Tutorial, PHP Tutorial example, learn PHP Include, online tutorial, download tutorial, PHP Tutorial books, PHP Tutorial videos, live videos PHP Tutorial, learn PHP Tutorial, PHP Tutorial topic PHP Include, live training PHP Tutorial, download free tutorial