logo
PHP Include and Require Files
The include() and require() statement allow you to include the code contained in a PHP file within another PHP file.  Including files is very useful when you want to include the same PHP, HTML, or text on multiple pages of a website.

You can save a lot of time and work through including files. Just store a block of code in a seperate file and include it whereever you want by include() and require() statement instead of typing the entire block of code multiple times. A typicall example is including the header, footer and menu file in all the pages of a website.

The basic syntax of the include() and require() statement  :
include("filename.php");   (or)  include "filename.php";
require("filename.php");   (or)  require "filename.php";
header.php
<div class="header">This is Sample Header</div>
<div class="nav_bar">
<ul>
    <li><a href="http://www.freetimelearning.com" target="_blank"> Home </a></li>
    <li><a href="http://www.freetimelearning.com/html5-tutorial.php" target="_blank"> HTML5 </a></li>
    <li><a href="http://www.freetimelearning.com/css3-tutorial.php" target="_blank"> CSS3 </a></li>
    <li><a href="http://www.freetimelearning.com/javascript-tutorial.php" target="_blank"> JavaScript </a></li>
    <li><a href="http://www.freetimelearning.com/php-tutorial.php" target="_blank"> PHP </a></li>
</ul>
</div>
footer.php
<div class="footer">
	All &copy; rights reserved <?php echo date("Y");?> by <a href="http://www.freetimelearn.com" class="footer_a" target="_blank">Free Time Learn.</a>
</div>
PHP Include Files Example :
<!DOCTYPE html>
<html>
<head>
    <title>PHP Include Files</title>
    <link rel="stylesheet" href="style-sheet.css" type="text/css">
</head>
       
<body>

<div class="main">
<!-- Start Header Part -->
<?php 
	include('header.php'); 
	//require('header.php');
?>
<!-- End Header Part -->

<!-- Start Content -->
	<div class="content">
    	<h4>Sample Content</h4>
        <p style="word-wrap:normal;">
            Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
            Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. 
            It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
            It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, 
        and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
        </p>
    </div>
<!-- End Content -->

<!-- Start Footer -->
<?php 
	//include('footer.php'); 
	require('footer.php');
?>
<!-- End Footer -->
  
</div>

</body>
</html>
Output :        Download !