PHP Include Files


Server Side Includes (SSI) are used to create functions, headers, footers, or elements that will be reused on multiple pages. You can insert the content of a file into a PHP file before the server executes it, with the include or require function. This can save the developer a lot of time.

The include Function
The include function takes all the text in a specified file and copies it into the file that uses the include function.

1.php 2.php
 <html><body>
 <?php
   include( "2.php" );
   echo  " is a " . $sex;
 ?>
 </body></html>
 <?php
   echo  $name;
 ?>
$name =   $sex = boy girl    

The require Function
The require function is identical to include except
  • The include function generates a warning (but the script will continue execution).
  • The require function generates a fatal error (and the script execution will stop after the error).
 <html><body>
 <?php
   include( "NoSuchFile.php" );
   echo  "This is a test.";
 ?>
 </body></html>
 <html><body>
 <?php
   require( "NoSuchFile.php" );
   echo  "This is a test.";
 ?> 
 </body></html>
 
 




      What’s the difference between a hippo and a Zippo?    
      One is really heavy, and the other is a little lighter.