PHP

PHP File Inclusion

PHP File Inclusion

The following functions are used to include one PHP file into another PHP file. These functions are used in creating functions, headers, footers, or elements that can be reused on multiple pages. This reduces the efforts of developers to change the layout of the complete website. If there are any changes to be made then only by changing the included file it can be done. 

  • The include() function –  this function is used to take all the text of the specified file and then copies all of it into a file that has an include function. In case there is any problem in loading a file the include() function will generate a warning while the script will continue to execute.
  • The require() function - this function is used to take all the text of the specified file and then copies all of it into a file that has an include function. In case there is any problem in loading a file the function will generate a fatal error and halts the execution of the script. 

The only difference between the include() and require() function is that it handles error correction differently. The require() function is recommended because if the files are misnamed or missing then the script should not continue to execute.