![]() | |||||||
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: PHP Code: Do this for the footer of each page as well, except enter the code below: PHP Code: 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 |
FAQ: The difference between include() and require() This is a question I get asked so many times, I'll clear it up here and now... In the probable event that the language above has not made anything about the two functions any clearer, the main difference is that the require() function will cause a fatal error to appear on your site where as include() will only give you a warning if it can't find the file. More from where that came from @ http://www.the-dev.net |
VERY VERY useful information. As you can see I have merged them into one thread called PHP require() & include(). Thanks a lot :) |
No problem, good idea for merging them - should've thought of that meself. Cheers, Dave :) |
Thanks for the good info! |
I never knew there was a difference between the two. Thanks for a great badic tutorial on the two functions! :) |
| All times are GMT -7. The time now is 07:20 PM. |
Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0