Llamasery.com Home  
 
Server-side Starter Tutorial: Includes - Part 6 of 6
Alfie the alpha_geek: Llamasery guru-in-waiting Tutorials Purpose

Starter Tutorials

Tell-a-Friend
Tell-a-Friend +
The 'Contact Form'
php Includes
Simple Themes
MySQL database 101
Comments System
Text Files

Intermediate Material

Articles/Tutorials

The End

There you have it. 'Smart includes' is what php can do for you. Time- and effort-saving stuff. Limited only by your own ingenuity and specific requirements. One thing that should be apparent (and I'll state it here so you will notice it) is that using includes works a lot better when you think things through before you actually begin coding. That doesn't stop you from converting an all-HTML site to one that uses includes of course, but you'll soon wish you had used includes from the start.

A useful 'trick'

If you always use the same 'top' file, then every page of your site will display the same title in the browser. Not exactly a good idea, but fortunately there's a very, very simple fix.

In your top.php file replace the HTML title code (<title>My Page</title>) with this:

<?
echo "<title>";
echo $page_title;
echo "</title>"
?>

That will automatically print the value of the variable $page_title as your page title. And in each of your php pages, declare the value of that variable. For example:

<?
$page_title = "your page title";
include("top.php");
?>
your page content
<?
include("bottom.php");
?>

include filename extensions?

In this tutorial, I've used filename.php consistently. Some people prefer to use .inc as the filename extension so they'll remember it's a file to be included as opposed to a .php file which they reserve for 'executable' files. Some people will use .tpl as the filename extension so they'll rememeber it's a template file. It doesn't matter which you prefer, they all work. Cautionary note: some restrictions apply - but only for files that include 'sensitive' information like passwords or usernames. That topic will be discussed in our tutorial on databases.

printer friendly pageHappy Including