Lost Password?


  #1 (permalink)  
Old 06-28-2006, 10:08 PM
Dan Dan is offline
Programmer
 
Join Date: Jun 2006
Posts: 145
Rep Power: 9
Dan is on a distinguished road
Default TUTORIAL: Save time using the PHP include Function <?php include

One of the main problems faced by webmasters is saving time when it comes to creating websites. When starting a website, one may choose to create a navigation menu like the following to link to each page:

Code:
<a href="http://www.yoursite.com/index.htm">Home</a> - 
<a href="http://www.yoursite.com/about.htm">About Us</a> - 
<a href="http://www.yoursite.com/links.htm">Links</a> - 
<a href="http://www.yoursite.com/contact.htm">Contact Us</a>
Which looks like: HomeAbout UsLinksContact Us

So now, you have your 4 pages - and all is well. But, as the site expands you need to integrate a forum - which leaves you with 4 pages to update. No problem at all... But supposing the site had 100+ pages! That would be a very monotonous time consuming job.

This is where we bring in the php include command to really speed things up!

Create just the navigation menu on its own, and rename all of your pages to .php

In this case, the navigation menu will look like this:

Code:
<a href="http://www.yoursite.com/index.php">Home</a> - 
<a href="http://www.yoursite.com/about.php">About Us</a> - 
<a href="http://www.yoursite.com/links.php">Links</a> - 
<a href="http://www.yoursite.com/contact.php">Contact Us</a>
Which looks like: HomeAbout UsLinksContact Us

Save this file as "menu.inc" as we will be including it elsewhere - hence the .inc extension.

Now, open up your .php pages that the menu links to, and simply add the following code at the very top, to include the navigational menu on the pages:

Code:
<?php include("menu.inc"); ?>
The code is telling the php page, to "include" the menu.inc file - and it does!

Once this has been added, any changes in the menu.inc file are reflected across the whole site making updating a lot easier!

Why stop at menus? This can be utilised for adverts, footers, headers, templates and much much more!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 07-02-2006, 04:59 PM
Lop's Avatar   
Lop Lop is offline
Speaks fluent binary
 
Join Date: May 2006
Posts: 1,149
Rep Power: 18
Lop will become famous soon enoughLop will become famous soon enough
Default

I includes like this to do most of my PHP work. I don't see a point typing the same info over again and if you want to change it you would have to change it on each page. With include you change once.
__________________
Lop
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-03-2006, 03:42 AM
Dan Dan is offline
Programmer
 
Join Date: Jun 2006
Posts: 145
Rep Power: 9
Dan is on a distinguished road
Default

Quote:
Originally Posted by Lop
I includes like this to do most of my PHP work. I don't see a point typing the same info over again and if you want to change it you would have to change it on each page. With include you change once.
Exactly the reason why I started using PHP! Of course once I discovered the powerful stuff it could do I never look back, I now build all websites in PHP.

Hope some strictly HTML users find this tutorial useful!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-05-2006, 12:41 PM
DevilsCharm's Avatar   
DevilsCharm DevilsCharm is offline
Programming God
 
Join Date: Jul 2006
Posts: 887
Rep Power: 14
DevilsCharm is on a distinguished road
Default

This is some PHP that I do know, I use the php include function on all of my pages. I have a global header and global footer, so I have to use it at least twice on all pages (but on some pages I have a third one).
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 07-05-2006, 10:28 PM
Kaabi's Avatar   
Kaabi Kaabi is offline
Programming God
 
Join Date: Jul 2006
Posts: 884
Rep Power: 14
Kaabi is on a distinguished road
Default

PHP has a lot of great functions, but I haven't heard of a PHP include one before. But then again, I know very little about PHP.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 01-01-2007, 11:19 AM
xtraze xtraze is offline
Programming God
 
Join Date: Dec 2006
Location: Sri lanka
Posts: 921
Rep Power: 0
xtraze is on a distinguished road
Send a message via MSN to xtraze Send a message via Skype™ to xtraze
Default

I find this really helpful, does this obey the CSS or just show as default ?
can I put it inside a <div> ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP: Execution Time Function Jordan PHP Tutorials 18 11-21-2008 02:07 PM
PHP Introduction clookid PHP Tutorials 10 01-16-2007 08:17 AM


All times are GMT -5. The time now is 08:58 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads