Categories
First Category

PHP include

The PHP include statement is very powerful to use when creating a web page layout. PHP include makes it possible to insert one or several html pages in another html page. It makes it easy to show common components correctly throughout your web pages, such as headers, menus (links), footers etcetera. For instance, the menu for all your web pages can be stored in one single file and then inserted in all web pages by using PHP include.

The PHP include statement is very powerful to use when creating a web page layout. PHP include makes it possible to insert one or several html pages in another html page. It makes it easy to show common components correctly throughout your web pages, such as headers, menus (links), footers etcetera. For instance, the menu for all your web pages can be stored in one single file and then inserted in all web pages by using PHP include. In this way it is also very easy to change the header, menu and footer for all web pages at once and you can be sure that all web pages are showing the same information.

PHP include example

Let’s look at a PHP include example. You want to use a common header, menu and footer for all your web pages:

  1. Create a file called “header.php” and fill it with the html code that you want to appear in the header of all web pages.
  2. Create another file called “menu.php” and fill it with the html code for the menu you want to use in all web pages.
  3. Create a third file called “footer.php” and fill it with the html code that you want to appear in the footer of all web pages.
  4. Then insert the header, menu, and footer in your web pages by using PHP include:
<html>
<body>

<?php include("header.php"); ?>
<?php include("menu.php"); ?>

<p>This is the ordinary web page content below the 
header and menu and above the footer</p>

<?php include("footer.php"); ?>

</body>
</html>

 

Leave a Reply

Your email address will not be published. Required fields are marked *