PHP Includes
So you want to use php on your site huh? It's easy to do lets get started!Create and code your layout as you usually would. Let's say my layout is using div layers my coding would look something like this:
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css">
<title>Site Title</title>
</head>
<body>
<div id="container">
<img src="image.jpg" border="0">
</div>
<div class="content">
<h1>Content Title</h1>
content content content content content content content content content
content content content content content content content content content
content content content content content content content content content
content content content content content content content content content
content content content content content content content content content
content content content content content content content content content
content content content content content content </div>
<div id="sidebar">
<div class="sidebarhead">Navigation</div>
<a href="#" class="nav">Link</a>
<a href="#" class="nav">Link</a>
<a href="#" class="nav">Link</a>
<a href="#" class="nav">Link</a>
<br />
<div class="sidebarhead">Side Title</div>
content content content content content content content content content
content content content content content content content content content
content content content content content content content content content
<br />
</div>
</div>
</body>
</html>
<head>
<link rel="stylesheet" href="style.css" type="text/css">
<title>Site Title</title>
</head>
<body>
<div id="container">
<img src="image.jpg" border="0">
</div>
<div class="content">
<h1>Content Title</h1>
content content content content content content content content content
content content content content content content content content content
content content content content content content content content content
content content content content content content content content content
content content content content content content content content content
content content content content content content content content content
content content content content content content </div>
<div id="sidebar">
<div class="sidebarhead">Navigation</div>
<a href="#" class="nav">Link</a>
<a href="#" class="nav">Link</a>
<a href="#" class="nav">Link</a>
<a href="#" class="nav">Link</a>
<br />
<div class="sidebarhead">Side Title</div>
content content content content content content content content content
content content content content content content content content content
content content content content content content content content content
<br />
</div>
</div>
</body>
</html>
It doesn't matter if your sidebar or whatever coding comes before or after your main page content. Now you need to break this up into 3 pages. First we want to identify all the coding that will be identical in all pages before your main content. In my example code that would be my starting HTML tags, my css information, and div positioning codes before my content title:
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css">
<title>Site Title</title>
</head>
<body>
<div id="container">
<img src="image.jpg" border="0">
</div>
<div class="content">
<head>
<link rel="stylesheet" href="style.css" type="text/css">
<title>Site Title</title>
</head>
<body>
<div id="container">
<img src="image.jpg" border="0">
</div>
<div class="content">
Now in a text editor make a new page using just that code and save it as header.php. Now we will look for identical coding again this time after the end of the main body of content, so in my example code that would be this:
</div>
<div id="sidebar">
<div class="sidebarhead">Navigation</div>
<a href="#" class="nav">Link</a>
<a href="#" class="nav">Link</a>
<a href="#" class="nav">Link</a>
<a href="#" class="nav">Link</a>
<br />
<div class="sidebarhead">Side Title</div>
content content content content content content content content content
content content content content content content content content content
content content content content content content content content content
<br />
</div>
</div>
</body>
</html>
<div id="sidebar">
<div class="sidebarhead">Navigation</div>
<a href="#" class="nav">Link</a>
<a href="#" class="nav">Link</a>
<a href="#" class="nav">Link</a>
<a href="#" class="nav">Link</a>
<br />
<div class="sidebarhead">Side Title</div>
content content content content content content content content content
content content content content content content content content content
content content content content content content content content content
<br />
</div>
</div>
</body>
</html>
Now you will want to make another new page using just that code and save it as footer.php. Now that you have those two pages done start a new page. This time copy the coding that will be your main page of content. (Your blog or whatever). In my example that would be the part below:
<h1>Content Title</h1>
content content content content content content content content content
content content content content content content content content content
content content content content content content content content content
content content content content content content content content content
content content content content content content content content content
content content content content content content content content content
content content content content content content<br />
content content content content content content content content content
content content content content content content content content content
content content content content content content content content content
content content content content content content content content content
content content content content content content content content content
content content content content content content content content content
content content content content content content<br />
Once you have pasted that to your new page, paste the code below at the top of the page before everything else:
<? include("/home/user/public_html/header.php"); ?>
Be sure to change /home/user/public_html/header.php to the absolute path to your header.php file, assuming it is in your root directory. If you don't know the absolute path to your root directory click here to find it.
Now at the very bottom of the page after everything insert this code:
<? include("/home/user/public_html/footer.php"); ?>
Again be sure to change /home/user/public_html/footer.php to the path to your footer.php file. Now save this file as index.php. Upload to your server and go to http://www.yoursite.com and your page should now display as coded. Congrats you just made a php include page.
To make sure all pages of your site follow this layout you will need to add the header and footer include codes above to the beginning and end of all content pages, just as you did with your index.php page. Be sure to save all pages using the .php extension. That's all there is to it. You now have a php site! Not too hard huh!






Oh wow,...


