include function provides one way to assemble pages.http://wyrd.hood.edu/third.php?hello_world
$_SERVER["QUERY_STRING"]
<html>
<head>
<title>breaking it up with PHP</title>
</head>
<body>
<h1>A demo of one way to assemble sites with PHP</h1>
<?php
$which = $_SERVER["QUERY_STRING"];
//The query string is the name of the content file to be included
if ( $which == "") {
// If there wasn't any content file name, give the home page
include "home.php";
}
else {
// Otherwise include the file whose name was provided
include $which;
}
?>
<hr />
<p>Footer Footer Footer Footer Footer </p>
</body>
</html>
The three content files are very short. They only contain the part that is different from page to page.
In this example they have been given the .php file extension, although it isn't necessary.
<h1>Welcome to PHP includes demo</h1> <p>This is the home page</p> <?php echo "How are you today?" ?>
<h1>Continued PHP includes demo</h1> <p>This is the second page. its content is inserted into the framework of the template. It is a very powerful technique for making a site easier to update.</p>
<h1>PHP includes demo continued some more</h1> <p>This is the third page.<br />The file contains only two lines of content, the part that is different from the other pages. The displayed page is a lot larger.</p>
This version of the example adds a set of navigation links. Now the beginning is.
<html> <head> <title>breaking it up with PHP</title> </head> <body> <a href="main2.php?home.php">HOME PAGE</a> | <a href="main2.php?second_page.php">SECOND PAGE</a> | <a href="main2.php?third_page.php">THIRD PAGE</a> <hr /> <p>A demo of one way to assemble sites with PHP</p>
The rest is the same
Subdirectory containing the example files.
For this exercise, create a multi-page site.
It should use the template technique with a home page and a second page.
Design the template yourself. Include navigation for the home page and the second page
For the home page content, use the content from your Lab 09 page.
For the second page content, write a couple of paragraphs explaining how the templating technique works.
Be sure to add the lab to your table of contents page and to complete the entry on Blackboard.
Hood College Department of Computer Science: Course materials © 1997-2006 by Elizabeth Chang.