ptg16476052
678 LESSON 24: Taking Advantage of the Server
Output ▼
Using PHP Includes
PHP and all other server-side scripting languages provide the ability to include snippets
of code or markup in pages. With PHP, the ability to include files is built in to the lan-
guage. Because the include statements are part of the language, you don’t need to include
parentheses around the name of the file to be included. You can conditionally include
files, specify which file to include dynamically, or even nest include function calls within
included pages. Here’s a simple example of an include call:
include "header.php";
On encountering that function call, PHP will try to read in and process a file named
header.php in the same directory as the current page. If it can’t find this file, it will try to
find the file in each of the directories in its include path, too. The include path is a list of
directories (generally specified by the server administrator) where PHP searches for files
to include, and it’s generally set for the entire server in a configuration file.
Four include-related functions are built in to PHP: require, require_once, include,
and include_once. All these functions include an external file in the page being pro-
cessed. The difference between include and require is how PHP reacts when the file
being included isn’t available. If include or include_once is used, the PHP page prints
FIGURE 24.2
A form with some
errors that were
caught during vali-
dation.
▼
▲