The include() and require() statements
includes and evaluate the specified file.
The two constructs are identical in every way except how they handle
failure. include() produces a Warning while require() results in a
Fatal Error.
Use require() if you want a missing file to halt processing of the page.
Example:
You can specify the include_path in the php.ini configuration file, default is:
include_path=".:/php/includes"Or provide an absolute path to the file you want to include.
When a file is included, parsing drops out of PHP mode and into HTML mode at the beginning of the target file, and resumes again at the end. For this reason, any code inside the target file which should be executed as PHP code must be enclosed within valid PHP start and end tags. Example:
Include and Variable Scope:
When a file is included, the code it contains inherits the variable
scope of the line on which the include occurs.
Handling Return Values:
It is possible to execute a return() statement
inside an included file in order to terminate processing in that file
and return to the script which called it.
The return value from the included file is the returned
by the include() function..
Example (include and return):
include_once() should be used in cases where the same file might be included and evaluated more than once during a particular execution of a script, and you want to be sure that it is included exactly once to avoid problems with function redefinitions, variable value reassignments, etc.