- Impact
- 0
PHP require() & include()
One of the most useful functions that PHP can perform are the require and include functions. These two functions are very similar in the action that they perform. They can call a page from anywhere in your directory (or another one) to a page. The most comment use for this is where headers and footers are involved.
Say, for instance, you have a 10 page web site and you need to edit the links of the page which happen to be text links and appear at the top of each page. With PHP instead of having to edit each page individually you can edit just one - which in the long run will save you a lot of time when editing your pages.
To achieve this, you need to split your page into three sections: a header, the main page and the footer.
Copy the header of the page into a new file and name this new file "header.php" and do the same for the footer, except name this file "footer.php". Then delete the "header" and "footer" from each of the other pages. Where the header of each file was enter this code:
Do this for the footer of each page as well, except enter the code below:
If you now upload all the pages, including the "header.php" and "footer.php" files and now, whenever you need to edit the header or footer of each page of each file, just open up the "header.php" and "footer.php" files and edit them - simple!
More where that came from @ http://www.the-dev.net
One of the most useful functions that PHP can perform are the require and include functions. These two functions are very similar in the action that they perform. They can call a page from anywhere in your directory (or another one) to a page. The most comment use for this is where headers and footers are involved.
Say, for instance, you have a 10 page web site and you need to edit the links of the page which happen to be text links and appear at the top of each page. With PHP instead of having to edit each page individually you can edit just one - which in the long run will save you a lot of time when editing your pages.
To achieve this, you need to split your page into three sections: a header, the main page and the footer.
Copy the header of the page into a new file and name this new file "header.php" and do the same for the footer, except name this file "footer.php". Then delete the "header" and "footer" from each of the other pages. Where the header of each file was enter this code:
PHP:
<?php
require("header.php");
?>
Do this for the footer of each page as well, except enter the code below:
PHP:
<?php
require("footer.php");
?>
If you now upload all the pages, including the "header.php" and "footer.php" files and now, whenever you need to edit the header or footer of each page of each file, just open up the "header.php" and "footer.php" files and edit them - simple!
More where that came from @ http://www.the-dev.net