Go Back   Internet Business Forums > Design & Development

Reply
 
Thread Tools Display Modes
Old 26-02-2004, 08:18 PM   #1 (permalink)
Business Guru
 
Brian Turner's Avatar
 
Join Date: Dec 2003
Location: Near Inverness, Highlands, Scotland
Posts: 7,716
Default An Introduction to building pages with php include statements

How to build with php includes.

A very simple web page may be built in HTML as follows:

Code:
<html>

<title>This is the Title</title>

<head>

</head>

<body>

<p>This is some text>

<p>This is some more text</p>

<p>Additional text</p>

</body>

</html>
Let's call that file "index.html"

Now imagine that this page (or piece of code) is now separated into different pieces, like a large jigsaw.

Like this, for example:

Code:
<html>

<title>This is the Title</title>

<head>

</head>

<body>

<!-- start of section 1 --->

<p>This is some text>

<!-- end of section 1 -->

<!-- start of section 2 --->

<p>This is some more text</p>

<!-- end of section 2 -->

<!-- start of section 3 --->

<p>Additional text</p>

<!-- end of section 3 -->

</body>

</html>
Now, imagine that we completely break up the page over more than one file (there is a reason for this!).

We can do this by using php include statements for the different sections.

Thus we create a text file with the following information added:

Code:
<!-- start of section 1 --->

<p>This is some text>

<!-- end of section 1 -->


and we then name this file as "section1.php"



We do the same for section 2 and section 3, naming them appropriately, ie:

section2.php:

Code:
<!-- start of section 2 --->

<p>This is some more text</p>

<!-- end of section 2 -->
section3.php

Code:
<!-- start of section 3 --->

<p>Additional text</p>

<!-- end of section 3 -->


To call up these files in PHP, we now create a text file and add the following information:



Code:
<html>

<title>This is the Title</title>

<head>

</head>

<body>

<?PHP include("/home/business/public_html/section1.php"); ?>

<?PHP include("/home/business/public_html/section2.php"); ?>

<?PHP include("/home/business/public_html/section3.php"); ?>

</body>

</html>
and we name this file "index.php"

We need to give it the extension ".php" to allow the server to execute the code, as PHP is a server side language and not a browser -based language.



NOTE: "/home/business/public_html/section1.php" is the path to file for the server. This may differ on different machines, but can be easily found out via an administration panel, or else by asking your webhost.



WHY THIS IS IMPORTANT

For many websites, only the main text area ever changes significantly.

However, sometimes fundamental changes need making to the rest of the website.

The example above only deals with text being called up as a php include - but imagine for a moment that your page header, page navigation bar, main content, and page footer, are all called up in this way as php include statements.

Now imagine that you need to change some element of your site: perhaps you wish to add an extra option in your navigation bar.

If you built a website entirely in HTML, you would likely have to change every single page to do this. On sites of hundreds, even thousands of pages, this can become impractical.

When if you have built your site pages using php include statements, such as your navigation bar, then to add something to it you merely change that one single file, and every single page that calls it up is now changed.

In fact, if you build a website with php include statements, and the main text area is the only part that ever really changes, then you can completely overhaul your entire site design by doing nothing more complicated than editing a handful of files.

Another advantage is that you can begin to use scripts to add random elements to the content. For example, at www.comparative-religion.com, every single page on the main site calls up two random php include statements on the right hand side: one of which informs of somewhere else interesting to visit on the main site, while the other informs of somewhere interesting to visit on the forums.

php includes are an incredibly powerful way to build up a website, because you only ever need to edit a couple of files to change the overal layout and look of perhaps thousands of pages.







__________________
SEO specialist
Brian Turner is offline   Reply With Quote
Old 30-01-2005, 02:53 PM   #2 (permalink)
Junior Member
 
Join Date: Jan 2005
Location: East Sussex UK
Posts: 7
Default Re: An Introduction to building pages with php include statements


Hello All,
I create a page called index.php shown above...its just a 3 tables

header.php usually contains your site banner , logo etc
footer.php usually contains your copyright info or replicates menu links
menu.php your site menu
NOTE: header, footer, and menu.php contain NO html opening or closing tags as they are all inserted within the BODY tags of of INDEX.php.


You can expand on this by making header.php call php functions from from another file. making them available to the page.

Hope this helps someone

Last edited by Webby Muller; 30-01-2005 at 03:04 PM.
Webby Muller is offline   Reply With Quote
Old 30-01-2005, 09:46 PM   #3 (permalink)
Business Guru
 
Brian Turner's Avatar
 
Join Date: Dec 2003
Location: Near Inverness, Highlands, Scotland
Posts: 7,716
Default Re: An Introduction to building pages with php include statements

Indeed - include statements are simply superb.
__________________
SEO specialist
Brian Turner is offline   Reply With Quote
Old 26-02-2005, 12:32 PM   #4 (permalink)
Junior Member
 
Join Date: Feb 2005
Posts: 1
Default Re: An Introduction to building pages with php include statements

Yes, for me it sure helps in maintaining my code. But I'd like to know how it affects search engine results. Can some please shed some light on this matter?

And let me add, there is also an include_once() function. ;-)
ahah is offline   Reply With Quote
Old 26-02-2005, 01:12 PM   #5 (permalink)
Business Guru
 
Brian Turner's Avatar
 
Join Date: Dec 2003
Location: Near Inverness, Highlands, Scotland
Posts: 7,716
Default Re: An Introduction to building pages with php include statements

Hi ahah, and welcome to Platinax.

As for search engines - they never see the code - it is all processed on the server *before* the pages are published to the net. So in its simplest form, it is can become just a more dynamic way of working with HTML.
__________________
SEO specialist
Brian Turner is offline   Reply With Quote
Old 06-04-2005, 10:47 AM   #6 (permalink)
Senior Member
 
vpssupport's Avatar
 
Join Date: Mar 2005
Location: Bedfordshire
Posts: 155
Default Re: An Introduction to building pages with php include statements

How can you test your includes locally? I am assuming you can only test it via your webserver that holds the php files.
__________________
Regards,
Clive Rutherford
www.vitalproductsolutions.co.uk
vpssupport is offline   Reply With Quote
Old 06-04-2005, 11:00 AM   #7 (permalink)
Business Guru
 
Brian Turner's Avatar
 
Join Date: Dec 2003
Location: Near Inverness, Highlands, Scotland
Posts: 7,716
Default Re: An Introduction to building pages with php include statements

You can download PHP and run it on your machine.

However, to be honest, I much prefer to leave my php files as text files, and test them only once uploaded to a server. IMO, it saves on clicking, and any errors that show in real publishing are often very quick and easy to correct.
__________________
SEO specialist
Brian Turner is offline   Reply With Quote
Old 06-04-2005, 11:42 AM   #8 (permalink)
Senior Member
 
vpssupport's Avatar
 
Join Date: Mar 2005
Location: Bedfordshire
Posts: 155
Default Re: An Introduction to building pages with php include statements

Thanks Brian!!! maybe you should setup a donation box lol!!
__________________
Regards,
Clive Rutherford
www.vitalproductsolutions.co.uk
vpssupport is offline   Reply With Quote
Old 06-04-2005, 02:36 PM   #9 (permalink)
Business Guru
 
Brian Turner's Avatar
 
Join Date: Dec 2003
Location: Near Inverness, Highlands, Scotland
Posts: 7,716
Default Re: An Introduction to building pages with php include statements

Hey, I'm always open to suggestions.
__________________
SEO specialist
Brian Turner is offline   Reply With Quote
Old 06-04-2005, 05:58 PM   #10 (permalink)
Senior Member
 
Join Date: Mar 2005
Location: UK
Posts: 122
Default Re: An Introduction to building pages with php include statements

The way I prefer to test PHP locally is to use my local installation of Apache, PHP and MySQL. I installed them separately, but you could choose to use a package such as WAMP to help you install all three.
__________________
Will
XML Feed Generator - Free Windows Tool Creates XML RSS Feeds from Your Website.
Liverpool Web Design | Epson Compatible Ink Cartridges
WSC-Will is offline   Reply With Quote
Reply

Thread Tools
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 Off


All times are GMT +1. The time now is 08:53 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.