•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 397,625 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,461 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 29965 | Replies: 3
•
•
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,881
Reputation:
Rep Power: 32
Solved Threads: 108
Basic Includes
Lets say you have a Web site with 10 or so pages, and you want to update the navigation. You don't want the hassle of updating every single page. That's where includes come in handy.
Your basic include will look like this.
[php]
<?php include ( 'includes/navigation.php' ); ?>[/php]
That's it! What I typically do is design a page as usual, then begin breaking sections up into includes. To use this effectively:
1) Find sections or tables that will repeat throughout the site.
2) Cut the section of code out and paste it into another file.
3) Save this file into an includes folder.
4) Where the original section was, insert your PHP inclue code, referencing the file name.
Let's say I want to use the highlighted code on multiple pages.
[php]
<table>
<tr>
<td>
This table will be on every page.
</td>
</tr>
</table>
<table>
<tr>
<td>
This is some other content.
</td>
</tr>
</table>[/php]
I'll include it like this.
[php]
<?php include ( 'includes/table.php' ); ?>
<table>
<tr>
<td>
This is some other content.
</td>
</tr>
</table> [/php]
Now if I change table.php later, it will change on every page automatically. It's just like using image tags, but instead of image files, you are including pieces of html. This can save you hours and hours.
Alan Hettinger is a freelance designer available for print, web, and multimedia projects.
Lets say you have a Web site with 10 or so pages, and you want to update the navigation. You don't want the hassle of updating every single page. That's where includes come in handy.
Your basic include will look like this.
[php]
<?php include ( 'includes/navigation.php' ); ?>[/php]
That's it! What I typically do is design a page as usual, then begin breaking sections up into includes. To use this effectively:
1) Find sections or tables that will repeat throughout the site.
2) Cut the section of code out and paste it into another file.
3) Save this file into an includes folder.
4) Where the original section was, insert your PHP inclue code, referencing the file name.
Let's say I want to use the highlighted code on multiple pages.
[php]
<table>
<tr>
<td>
This table will be on every page.
</td>
</tr>
</table>
<table>
<tr>
<td>
This is some other content.
</td>
</tr>
</table>[/php]
I'll include it like this.
[php]
<?php include ( 'includes/table.php' ); ?>
<table>
<tr>
<td>
This is some other content.
</td>
</tr>
</table> [/php]
Now if I change table.php later, it will change on every page automatically. It's just like using image tags, but instead of image files, you are including pieces of html. This can save you hours and hours.
Alan Hettinger is a freelance designer available for print, web, and multimedia projects.
Last edited by cscgal : Mar 14th, 2004 at 11:58 am.
Dani the Computer Science Gal
Do you run a computer-related website? Feature it in our niche link directory!
Do you run a computer-related website? Feature it in our niche link directory!
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
Similar Threads
- Basic PHP (PHP)
- Test For Php Includes (PHP)
- PHP Includes??? (PHP)
- Setting up PHP (PHP)
- Hosting multiple Apache/PHP/mysql sites - how many? (Linux Servers and Apache)
- Multiple PHP INCLUDES (PHP)
Other Threads in the PHP Forum
- Previous Thread: if file exists
- Next Thread: Sending Emails




Threaded Mode