PHP Includes

PHP includes may seem very difficult to understand at first but once you get the hang of it, they will simplify your life like anything ever could! lol! Once you learn PHP including, you can do the following things with your website:
» Make it more organized.
» Change layouts with ease.
» Add cool PHP scripts.
» Add same text/content to many pages with ease.
» Skin your site!
Though skinning is another big thing, which will need more tutorials and lots of patience.

Tutorial

First of all, code a layout for your site with normal HTML like you always do. For startes lets assume you are using a Div-Layers layout, Your typical coding will be something like this:



We now have to divide this HTML code into 2 parts, or more if you want. Open your text editting program, I use notepad. Copy and paste html of the page upto the portion, which defines features which will be common for all pages of your site. For example, in the above page, The code that can be common in all pages of the site will be :



This means, the starting HTML code, including CSS link, top image, the navigation and the the main content position will be same for all the pages on site. Save this file as header.txt or header.php
Start a new document in notepad and copy & paste the rest of HTML code of the page, in the above example it will be:



Save this file as footer.txt or footer.php. Now start a new document in notepad and copy & paste the code below there:



Save this file as index.php. In the code above, change header.php and footer.php to header.txt and footer.txt respectively, if you saved them as .txt files. You need to change the User with the username, folder with the name of folder where all your files are or your subdomain, the header and footer files that is. If you have them in root directory remove the folder from the path. For those who are hosted, you need to ask your host, the username
. For example is the username is bunny, your subdomain is hop, (assuming your files are in the root directory) the code will be something like this:



I hope thats understandable. Upload index.php to your root directory, now go to your site, (http://yoursite.com/index.php) if it shows you the layout exactly the way you coded it, congrats! You just made your first php page!