PHP Include - Require
PHP Include - Require
Syntax:
include 'filename';
or
require 'filename';
Note: Including files saves a lot of work. This means that you can create a
standard header, footer, or menu file for all your web pages. Then, when the
header needs to be updated, you can only update the header include file.
Example:
footer.php:
<?php
?>
Welcome.php
<html>
<body>
<h1>Welcome to my home page!</h1>
<p>Some text.</p>
</body>
</html>
Example: index.php
<?php
include_once('header.php');
include_once('heade.php');
?>
Both functions work as same and produce same output but if any error arises
then differences come.
Example:
If we don’t have a file named header.php, then in the case of the
include_once(), the output will be shown with warnings about missing file, but
at least the output will be shown from the index.php file.
In the case of the require_once(), if header.PHP file is missing, then a fatal
error will arise and no output is shown and the execution halts.