pulse__xx
Member
- Messages
- 350
- Reaction score
- 0
- Points
- 16
PHP includes are an important part of PHP. With HTML sometimes it gets very annoying having to change everything if for example you change your layout, it can be very time consuming ! PHP includes break down this process so that can have a header.php file and a footer.php file and these will appear on every main page, so if you were to change your layout you would only have to change these two files !
1. Here is an example of the HTML page, it is a very simple page to make it easier for you to understand. Basically this coding would be on every individual page but the only bit that would change would be where the content is. So you see how inefficient this is?
<head>
<title>Your page title</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="content">Main content here</div>
<div id="footer">Copyright</div>
</body>
2. Take the top part of your coding that is always the same with each page
<head>
<title>Your page title</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
Now paste this into notepad and save it as header.php
3. Take the bottom part of the coding that is the same with each page.
<div id="footer">Copyright</div>
</body>
Now paste this into notepad and save it as footer.php
4. Now you will be left with the middle part... this should change with each page as this is the actual content. So now we can join this together
<?PHP include ("header.php"); ?>
<body>
<div id="content">Main content here</div>
<?PHP include ("footer.php"); ?>
Now you could name this file content.php, or whatever, but make sure it ends in .php ! and for another page for example tutorials.php you could use the same coding, eg
<?PHP include ("header.php"); ?>
<body>
<div id="content"><b>Tutorials</b>
<br>
List of tutorials here
</div>
<?PHP include ("footer.php"); ?>
The header and footer will be the same, just the content will change, so then if you decide to change your layout, you will only need to edit header.php and footer.php!
Sysque Studios for more tutorials.
This tutorial is brought to you by http://so-you.net/
1. Here is an example of the HTML page, it is a very simple page to make it easier for you to understand. Basically this coding would be on every individual page but the only bit that would change would be where the content is. So you see how inefficient this is?
<head>
<title>Your page title</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="content">Main content here</div>
<div id="footer">Copyright</div>
</body>
2. Take the top part of your coding that is always the same with each page
<head>
<title>Your page title</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
Now paste this into notepad and save it as header.php
3. Take the bottom part of the coding that is the same with each page.
<div id="footer">Copyright</div>
</body>
Now paste this into notepad and save it as footer.php
4. Now you will be left with the middle part... this should change with each page as this is the actual content. So now we can join this together
<?PHP include ("header.php"); ?>
<body>
<div id="content">Main content here</div>
<?PHP include ("footer.php"); ?>
Now you could name this file content.php, or whatever, but make sure it ends in .php ! and for another page for example tutorials.php you could use the same coding, eg
<?PHP include ("header.php"); ?>
<body>
<div id="content"><b>Tutorials</b>
<br>
List of tutorials here
</div>
<?PHP include ("footer.php"); ?>
The header and footer will be the same, just the content will change, so then if you decide to change your layout, you will only need to edit header.php and footer.php!
Sysque Studios for more tutorials.
This tutorial is brought to you by http://so-you.net/
Last edited: