|
|
#1 (permalink) |
|
Business Guru
Join Date: Dec 2003
Location: Near Inverness, Highlands, Scotland
Posts: 7,716
|
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> 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> 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 --> 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>
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 |
|
|
|
|
|
#2 (permalink) |
|
Junior Member
Join Date: Jan 2005
Location: East Sussex UK
Posts: 7
|
![]() 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. |
|
|
|
|
|
#4 (permalink) |
|
Junior Member
Join Date: Feb 2005
Posts: 1
|
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. ;-) |
|
|
|
|
|
#5 (permalink) |
|
Business Guru
Join Date: Dec 2003
Location: Near Inverness, Highlands, Scotland
Posts: 7,716
|
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 |
|
|
|
|
|
#7 (permalink) |
|
Business Guru
Join Date: Dec 2003
Location: Near Inverness, Highlands, Scotland
Posts: 7,716
|
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 |
|
|
|
|
|
#10 (permalink) |
|
Senior Member
Join Date: Mar 2005
Location: UK
Posts: 122
|
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 |
|
|
|