1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

Including External Files in PHP

By

1 of 3

Include and Require
PHP is capable of utilizing SSI to include an external file into the file being executed. Two commands that do this are INCLUDE () and REQUIRE (). The difference between them is that when placed within a false conditional statement, the INCLUDE is not pulled but the REQUIRE is pulled and ignored. This means that in a conditional statement it can be faster to use INCLUDE. These commands are phrased as such:

 INCLUDE 'http://www.yoursite.com/path/to/file.php' ; 

//or

REQUIRE 'http://www.yoursite.com/path/to/file.php' ;

Some of the most common uses for these commands include holding variables that are used across multiple files or holding headers and footers. If an entire site's layout is housed in external files called with SSI, any changes to site design need only be made to these files and the entire site will change accordingly.

Related Video
Basic PHP Syntax
Using PHP With HTML
  1. About.com
  2. Technology
  3. PHP / MySQL
  4. Advanced PHP
  5. Include Files Inside Other PHP Files

©2014 About.com. All rights reserved.