To include a PHP file into an opened PHP script we may use one of following two possible groups of statements:
- The require and require_once statements
- The include and include_once statements
The require statement after being called will add the required file's source code into the source code where it is called from.
NOTE: The difference between the require and include statements is that the require statement in case of a failure produces an error and halts the script, while on the other hand, the include statement will only produce a warning and continue with the script.
The require_once statement is similar to the require statement except the script will check if the file has already been included in the script.
Syntax for REQUIRE statement
<?php
require "file.php";
?>
Example with REQUIRE_ONCE statement
<?php
require_once(_ROOT_."/config.php");
?>
Comments
No comments have been made yet.
Please login to leave a comment. Login now