PHP Include Files
PHP Include Files allow you to reuse code by inserting the contents of one PHP file into another. This is especially useful for common elements like headers, footers, or configuration files. PHP provides several ways to include files:
Basic Syntax
Or
Difference Between include
and require
Function | Behavior if File is Missing |
---|---|
include |
Shows a warning, script continues |
require |
Shows a fatal error, script stops |
Example Usage
header.php
footer.php
index.php
Other Variants
-
include_once 'file.php';
– Includes the file only once, avoids re-inclusion. -
require_once 'file.php';
– Same as above, but stops execution on failure.