Let’s see what’s the difference between PHP include() Vs require(). In this tutorial, we are going to see the list of functions used in PHP to include an external file into a program. PHP provides various functions to include external files. The following list of functions is used to include an external file into a PHP program. We are going to see the purpose of the _once usage and the difference between include and include_once/require and require_once. include() require() include_once() require_once() include(): PHP include() function includes external file into a PHP program. It accepts the external file path and checks if the file exists or not. If the file does not exist in the specified path, then the include() will return PHP warning. include() function can be used in loops or control structure. Warning: failed to open stream: No such file or directory… Warning: Failed opening … for inclusion… By including an external file by using the PHP include() function, the variable, functions, and classes of the included file can be used in the program where it is included. The following code shows an example for including an external file using PHP include(). <?php include("../file_name.php"); // relative path //OR include("https://www.website.com/file_name.php"); // absolute path If we include the same file multiple time by using this function, then it will cause a PHP error. require(): PHP require() function is as similar as include() function. But, the difference is, the require() function will return a fatal error and stop executing the program at the time of failure where the include() function returns warning and continue execution. require() function can not be used in loops or control structures. Warning: failed to open stream: No such file or directory… Fatal error: Failed opening required… The code to include file using require() function is, <?php require("../file_name.php"); // relative path //OR require("https://www.website.com/file_name.php"); // absolute path include_once() and require_once(): The include_once() and require_once() functions are similar to the include() and require() functions, respectively. But, using this function will create difference at the time of including the same file for multiple time. By using include_once() and require_once() functions, will include the specified file if it’s not already included, otherwise, PHP will ignore this statement. The code is, <?php include_once("../file_name.php"); // relative path <?php require_once("../file_name.php"); // relative path Share this:Click to share on Twitter (Opens in new window)Click to share on Facebook (Opens in new window)Click to print (Opens in new window)Click to share on LinkedIn (Opens in new window)Click to share on Telegram (Opens in new window)Click to share on WhatsApp (Opens in new window)Like this:Like Loading... Post navigation Is PHP in 2019 still a relevant language Tips For Choosing a Web Development Company