Making Website Management Easier with PHP include()
November 27, 2009
page 1, 2, 3

If you have ever maintained a website, weather it was a small three or four page site or a much larger site, you have probably noticed that updating your pages can get a little tricky and in some cases, very repetitive. One helpful trick is to use the php command; include(). In this write-up, I am going to do my best to explain how helpful it can really be and what you will need to use it.

Correct me if I am wrong, but most websites tend to be made up of several pages and each of those pages have a few things in common. Usually a web page is made up of a logo/title area at the top; the bottom is usually your footer area (for contact or copyright information perhaps) and of course the website’s menu area. Who knows, there might be more areas of your website that are shared between pages, for this example, however, we’ll make it easy and stick with only the three mentioned; the header, the footer and the menu.

Now, when you first built your website you probably wrote the html for one page and made sure you had it set up just the way you wanted. For the rest of the pages, though, you might have just copied page one and then pasted it, only changing the actual content area of the page. There isn’t anything wrong with that, it’s perfectly fine and it works great. It makes programming the rest of your website so much easier and faster. The problem with that comes later down the road however.

Maybe a few months have gone by since your website went live and now you want to add, replace or even remove a page. Maybe you want to change your logo too. Easy, right? It may very well be but, remember; now you will need to revise each page separately. That means you will need to make several changes on each page making sure you do not make any mistakes while doing those changes. At first, making all these changes is not a big deal; in fact, it seems neat and fun because you feel like you are really learning something and becoming more and more familiar with html. After a few updates and changes to the site though, you will more-than-likely wish there was a quicker and easier way to make these site wide changes. This is where a little knowledge of php can be an enormous help.

Before getting too far into this you will need to check to see if your web server has php running. Most web servers will have some information describing what is available to its users. It might depend on what subscription or plan you have, so you may need to upgrade. Once you get that sorted out we can continue. You could also make a test.php file and then upload to your server and try to access the page.

To test if your web server has php running, simply open your text editor (Windows Notepad for example) and type the following (or cut and paste the following for that matter).

<?php
	echo (‘Does this work?’);
?>

Once you have done that, save the file as test.php and upload this file to your web server like you would upload your .html files. Now, all that is left to do is to check your new page. Go to http://www.yourwebsite.com/test.php. If everything is setup and operating properly you should see a simple message in your web browser: Does this work?. If nothing shows, it possible your web server doesn’t have php installed. You will need to contact your web server provider and see about getting it installed.

Hopefully the above test worked out perfectly and we can continue on. There really isn’t much more left to do at this point.

page 1, 2, 3

More Projects:
    Complete Project List

Making Website Management Easier with PHP include()
November 27, 2009
If you have ever maintained a website, weather it was a small three or four page site or a much larger site, you have probably noticed that updating your pages can get a little tricky and in some cases, very repetitive. One h...

Hi-def Video with VLC Media Player
November 18, 2009
I was having trouble watching hi-def or .mkv video files with VLC Media Player so I went looking for a solution. It was only a matter of checking one check box in the preferences menu...

Ubuntu Linux Info
April 03, 2009
This is where I will be keeping any and all of the information that has been very useful to me in setting up my Ubuntu system the way I want....

Software Alternatives
March 26, 2009
This is a list I have compiled of free software that can be used in place of far more expensive consumer products....

MAME Cabinet
April 05, 2008
My MAME cabinet build diary. (Taking much longer than I expected)...

© Copyright 2009-2010 schalfin.com