Switch to full style
:read: Start PHP with us. Includes topics to help you in php
Post a reply

PHP Include

Mon Sep 08, 2008 1:27 am

Can you imagine , write a pace of code once and use it many times .Any changes in this code you will only change in one file .it will be a nightmare if you duplicated the code in every place you wanted to use it .You have to go all over these code parts and do your update .you can do this in PHP by including the file you want to use.

suppose you are using an mean bar that you want to be visible in all your site pages for example
header.php
Code:
<html>
<body>
<a href="http://www.codemiles.com/index.php">Home</a> -
<a href="http://www.codemiles.com/about.php">About Us</a> -
<a href="http://www.codemiles.com/links.php">Links</a> -
<a href="http://www.codemiles.com/contact.php">Contact Us</a> 

and the output of this is :
Code:
Home - About Us - Links - Contact Us

Put links for sure, suppose now you want to add these links in your page .you will do the following :

index.php content is :
Code:

<?php include("header.php"); ?>
<p>My site home page !</p>
</body>
</html>


the HTML code that will be generated of index.php is :
Code:
<html>
<body>
<a href="http://www.codemiles.com/index.php">Home</a> -
<a href="http://www.codemiles.com/about.php">About Us</a> -
<a href="http://www.codemiles.com/links.php">Links</a> -
<a href="http://www.codemiles.com/contact.php">Contact Us</a>
<p>My site home page !</p>
</body>
</html>


making header and footer files for your site is a well known technique in web design.

hope this topic help you , thanks



Post a reply
  Related Posts  to : PHP Include
 get include path     -  
 Require vs Include in php     -  
 Using include() Within a Loop     -  
 Using include function     -  
 jsp include directive not working     -  

Topic Tags

PHP Functions