neskaya
Follow [ bookmark livejournal facebook twitter rss stumbleupon ]
Log in to download layouts, skins, and emoticons. Register?

Designs

Web Templates
LJ Layouts
phpBB3 Skins

Graphics

Avatars
Textures
Buttons
Emoticons
Pixels
Fonts

Misc & Fun

Quizzes
Tutorials
Interactive

Community

Forums
Rotation

Site

FAQ & Contact
Links

Affiliates

Komet Tails
Smile Scan
Dragonrain

PHP Tutorial: Include() Function [Change every page in one step]

The include function is definitely one of the most useful PHP functions ever! Especially if your web site has more than a few pages. I don't know what I'd do without it, especially since I don't use a CMS.

The include function allows you to change things simultaenously on multiple pages. For example, if your layout includes a sidebar, you don't want to have to go through every single page of your site to change the sidebar every time you want to modify something in it. You can put the entire sidebar contents in a different file and use the include function. The include function looks like <?php include("file.php"); ?> and it really doesn't matter whether you include HTML or PHP files.

The best way to demonstrate is through an example. Each of my individual pages on this site actually looks something like this:

<?php include("header.php"); ?>
Page content here.
<?php include("footer.php"); ?>

That's all the code that's written on my pages. Inside the header file, I may have other includes as well. The point is to make your whole site customizable through editing one page.

Explanation: All your code prior to your actual text/content for the page goes in header.php and all the code after it goes in the footer. This way you can easily alter your layout in multiple pages. See how it works? This makes life so much easier. The include function is amazing. Really.