PHP Require

The PHP require function is used to include the contents of another file wherever you insert the code.

You may also wish to read the lesson on the PHP include function.

As described in the include lesson, there is a difference between the way that the include function and the require function act.

The include function will continue to execute if it runs in to an error, while the require function will stop immediately if it runs in to an error.

What this means is that if you have an error when using the include function, you will get a warning, but the script will continue to execute (which will most likely cause troubles in the functionality). If, however, you are using the require function, you will get a fatal error and no further action is taken.

You would use the require function instead of the include function anytime you wish to halt the execution of your script when it runs into an error rather than continue to execute causing the script to malfunction.

Example:



You may also wish to read the lesson on the PHP include function.