Neskaya Forum Community Neskaya Chat Neskaya staff
Home

Tutorials

Articles (6)
HTML/CSS (15)
Javascript (3)
PHP (3)
Paint Shop Pro 7 (7)
Flash CS3 (9)

Design

Avatars (166)
Layouts (8)
phpBB3 Skins (4)
Buttons (20)
Fonts
Emoticons
Adopt

Quizzes

Classical Elements
Your Baby's Looks
Clothes Color
More (10)

Interactive

Button Rotation
Hosting
Livejournal

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.

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("beforecontent.php"); ?>
All my ramblings and individual page text goes here.
<?php include("aftercontent.php"); ?>
<?php include("sidebar.php"); ?>
<?php include("aftersidebar.php"); ?>

That's all the code that's written on my pages.

Explanation: beforecontent.php includes my code from my <html> tag through my header through the beginning of my tables until it's the space where I write the page content. aftercontent.php includes all of my code up until my sidebar content. sidebar.php, of course, is just the content in my sidebar. If you want to see the actual example, you can look here. Of course, the onclick effects don't work because the code for the script to that is in the beforecontent file! The aftersidebar.php includes the rest of the layout code until the </html> tag.

See how it works? This makes it so much easier when I want to change something in my layout or my sidebar, as I can just do it in the corresponding layout or sidebar.php file and it will apply to all of my pages. The include function is amazing. Really.



Forum

Latest Topics...
- Continuing Story OOC
- Hai Hai Everyone :3
- WE SHALL TALK ABOUT MUFFINS!
- Harle is a bastard
- messages of love



Site

Submissions
Terms of Use
Credits
Links & More


Site of the Month



Affiliates

None


 
Neskaya.Net is © Strawbee 2008. All rights reserved.
Best viewed in 1024 x 768 resolution or higher.


eXTReMe Tracker