GlowHost Web Hosting Forums  

Go Back   GlowHost Web Hosting Forums > In The Lounge > Programming Talk
Register Forum FAQ Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-27-2005
Matt's Avatar
chown -R us.us *YourBase*
 
Join Date: Jan 2005
Location: Moved to Florida!
Posts: 1,725
Rep Power: 10
Matt is a glorious beacon of lightMatt is a glorious beacon of lightMatt is a glorious beacon of lightMatt is a glorious beacon of lightMatt is a glorious beacon of lightMatt is a glorious beacon of light
Default PHP Includes - one file for everything

I am not much of a programmer, as I deal mostly with back-end server administration, but I thought I would lend likely the most valuable and time saving code snippit that I have came across for those of you that are interested.

Basically, this thread is about how to make one file, and have it displayed on all pages of your website. Why would this be useful? Well, for example if you had a header, footer, or navigation that is site-wide, you can edit ONE FILE and have it displayed on all pages of your website.

Imagine editing only one file instead of every page on the site when you need to add a new link to your navigation bar, or, in the example of glowhost.com, a common footer on every page.

Have a look:

http://glowhost.com/footer.php

Look familiar? If we need to edit a link or change something in the footer, we edit the one file, and it appears on every page in our website.

What a time saver!

To achieve this, it is a simple process.

First of all, you will need to make sure your document that includes any file like this to have a .php. extension, instead of .htm or .html

Lets now assume that you have your page named whatever.php, and in whatever.php you want to include a common footer like GlowHost.com does.

ll you need to do is make a page called footer.php (or whatever suits you best) and code it like a normal html document.

Now open up whatever.php in your html editor, and place this snippet in where you would like the footer to appear:

PHP Code:
<? include("footer.php"); ?>
This assumes that footer.php and whatever.php reside in the same directory.

PHP Code:
<? include("../footer.php"); ?>
would be the way to code it if your footer.php lived in the public_html folder, and the whatever.php lived in a subdirectory of public_html.

I hope you guys and gals find that as useful as I do!

__________________
:::::
01001100 00110011 00110011 00110111

Last edited by Matt; 11-10-2005 at 08:11 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 08-03-2007
rlhanson's Avatar
Master Glow Jedi
 
Join Date: Aug 2007
Location: Chapman, Kansas
Posts: 347
Rep Power: 35
rlhanson will become famous soon enough
Default

Thought I would elaborate on your snippet - which is, by the way, the single best thing I learned in web design!

Using your example, you can save footer.php as footer.html, or .htm to use the include statement - it doesn't have to be a php file.

You can save your document as an html or htm file if you configure your Apache Handlers in your cpanel or .htaccess for this: AddHandler application/x-httpd-php .html

An important note is, when using your editor (like dreamweaver) delete all the html which pre-exits when creating a new page (<HTML><HEAD><TITLE></TITLE></HEAD><BODY></BODY></HTML>) as you don't need any of this.
Just add your content to the page and save. With the php include statement, your included page is parsed as if it was part of the main document.
This snippet also HELPS with PAGE LOAD time dramatically!
Good advise there Matt!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-21-2008
Mirey86's Avatar
Newbie
 
Join Date: May 2008
Posts: 2
Rep Power: 0
Mirey86 is on a distinguished road
Default

Great guide, Matt!! Thank you very much.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 10-24-2008
dansgalaxy's Avatar
Junior Web Sage
 
Join Date: Jun 2008
Location: Swindon, UK
Posts: 10
Rep Power: 0
dansgalaxy is on a distinguished road
Default

The good old PHP include! couldnt live without it

Im getting to grips with Smarty templates at the mo on a project im working on, which are prety cool too!

Dan
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may post new threads
You may not post replies
You may not post attachments
You may 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



All times are GMT -5. The time now is 09:37 AM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO
Copyright 2000-2007 GlowHost.com