Server-side Starter Tutorial:Includes - Part 3 of 7

Let's make those 'included' bits

First, write this piece of code, and save it with the file name top.php:

<html>
<head>
<title>The Page</title>
</head>
<body bgcolor="white">

Next, write this piece of code, and save it with the file name bottom.php:

</body>
<html>

Finally, write this piece of code, and save it with the file name mypage1.php:

<?php
include("top.php");
?>
Hello World
<?
include("bottom.php");
?>

Testing Time

Copy all three files to your server, then navigate to mypage1.php. You'll see the simple Hello World page. View the HTML source to verify for yourself that it is exactly the same as the 'top', content, and 'bottom' that you created. That's as simple as 'includes' get.

Open mypage1.php in your favorite text editor, change "Hello World" to "Hello, My name is Bob" and save that file as mypage2.php. Open top.php and change body bgcolor="white" to body color="green". Save that file as top.php.

Copy top.php and mypage2.php to your server, then navigate to mypage2.php to see that it works and the background color is green. Then navigate to mypage1.php - notice that the background color is green. No matter how many pages you needed to change the background color for, that single change to top.php would affect every one of them. That's as simple a way of changing every page on your site as you can imagine.

«  previous  |  next  »  

Site Links

 

Starter Tutorials