now with added Masterweb and IB Geek Girl

spider web Ecanus•net :: Tutorials

Tutorials

These aren't really full blown tutorials – more quick 'n' dirty guides to doing stuff that might save you some time. Click the links below to see them.

Using "Includes"

Do you have sections of your pages that have identical information on every page? Come update time changing each bit on every single page can be extremely time-consuming and tedious. How can you make life easier for yourself...? Server Side Includes (SSI), or 'Includes' for short....read on...the squirrels who run this place are gonna be sooooo mad we're taking even more work away from them! <grin>

Anytime you find yourself updating the same information on more than one page, you most likely could have saved time by using includes – navigation, copyright notices, contact information – in fact anything that is on more than one page can use includes. Includes basically means using a separate file that is 'included' into your page. Here, we look at three methods of doing includes:

FrontPage

Step 1: Open a new blank page (File > New)

Step 2: Enter your content – in the design mode, type the information you want in the 'include', for example your copyright statement or your contact details. As well as text that is repeated on multiple pages you can have whole sections of your page in includes, for example your site navigation or footer, etc. Once your text or page section is finished, save it as a new page within the web that it's going to be an include for.

Step 3: Open the page in your web where you want to insert this new information. Place your cursor on the page, exactly where you want to insert the new information.

Step 4: In the menu, click on insert > web component. A new window will open. In this new window, under component type, click Included Content. Under Choose a type of content, click on page. Click Finish.

Step 5: A small window will open – Include page properties. Click on Browse. Browse to find the new page you just made and highlight it. Click ok in the browse window. Click Ok in the include page properties window. Save the page.

Step 6: Look at the page where you have included the new content. In design mode if you click on this areas, you will see a small hand holding paper. If you double click in that area it will bring you to the included content page. In preview mode however there's no indication the information is an include. In code view you would see code similar to this:

<!-- webbot bot="Include" u–include="footer_include.html" tag="BODY" -->

PHP

If the squirrels didn't like that one, they're sure not gonna like this! <grin>...php includes...

Step 1: So you've got your lovely page all ready to pop your include into? Create a page with the content you want included – just the content – no <html> tags, no <head> tags, no <body> tags, just your content. Save the new page with a '.php' file extension.

Step 2: At the place in your code where you want your included content, simply paste the following (obviously changing the filename to the name of your include file):

<?php include("myinclude.php"); ?>

Step 3: Upload both your files to your server, and view the result. (This obviously only works if your site's on a server that supports php – if you're not sure, check with your hosting provider).

ASP

ASP includes are virtually identical to PHP includes....

Step 1: You've got your lovely page all ready to pop your include into? Create a page with the content you want included – just the content – no <html> tags, no <head> tags, no <body> tags, just your content. You can include files with '.asp', '.html', '.txt' and other extensions.

Step 2: At the place in your code where you want your included content, simply paste the following (obviously changing the filename to the name of your include file):

<!--#include file="myinclude.asp" -->

Or if your file is in a different directory:

<!--#include virtual="/directory/myinclude.asp" -->

Step 3: Remember you need to save your final page with a an '.asp' extension, or it won't work right.

Step 4: Upload both your files to your server, and view the result.

Remember, in all the above examples, if your include file is in a different directory, make sure you've got the path right or it won't work! The most common problem with using includes is that either nothing gets included, or error messages appear where the 'include' should be saying that it can't be found.

Warning: main(myinclude.php) [function.main]: failed to open stream: No such file or directory in /home/username/public_html/includes/myinclude.php on line 39
Warning: main() [function.include]: Failed opening 'myinclude.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/username/public_html/includes/myinclude.php on line 39

The error message shown above is the type of message you'll get when using a PHP include where either the path for the included file is wrong, or you've forgotten to upload the file onto the server (or saved it in the wrong place). For portability, it's usually best to use relative file paths, but if the included file is in a different directory to the page it's included in, remember you'll need to specify it's directory as well as the filename. For example, if your include files are in a directory called "includes", the relative file path to your include file would be:

<?php include("includes/myinclude.php"); ?>

If the page you're including the file into is itself in a subdirectory, your file path for the included file will need to point to one directory higher...

<?php include("../includes/myinclude.php"); ?>

If it doesn't work first time, don't panic! Getting an include file path right can sometimes be a matter of trial and error if you're using a complex directory structure. It can often help in trying to get file paths right if you draw out your directory structure in a 'tree' diagram to help you visualise the relationship between different directories. And of course, before you start playing about with file paths, it always pays to double–check that you did actually upload the include file to the right directory on the server!

THE END