PHP Includes!

Have you ever found out about something that would have made your entire life so much easier? I had this experience recently with the concept of building websites using PHP includes.

In a nutshell, PHP includes allow you to build webpages using modular sections or code blocks.

PHP is, of course, a server-side scripting language, which means it can be used to create dynamic content for the web. With PHP you can interact with other applications on the server as well as do things like set cookies, process forms, store input in a database, etc. That’s great stuff, but most people may not need to take advantage of that. The thing most people need to know about is the use of PHP for creating multi-page websites using includes. One of the biggest problems (if you don’t use PHP) is making changes to an entire site. Let’s say for example you have a website with hundreds of individual pages. Without includes, you would have to download and edit each of those files to reflect the new changes. Even if you did some find-replace mojo, you’d still have to edit each of those pages and reupload them to the web server. But, if you use includes you could create a template that each page would use. When you needed to make changes you would simply change the content of the particular include. So, for example, any page on a site could be arranged like this:

header include (separate file like header.inc.php)
content
footer include (separate file like footer.inc.php)

To change the navigation in the header across the entire site, you would just alter the header.inc.php file instead of having to download and change each separate page.

2 comments

  1. i’ve seen some amaaazing php driven web sites/blogs, and have been wanting to learn it for some time now – are there any really easy and straightforward hands-on textbooks you can recommend?

    right now i’m studying vb.net in preparation for learning asp.net and it’s slow going, purely for graduation + improved job prospect purposes – i have a feeling php would be far less clunky.

  2. All I know how to do is includes! I will be trying to do more, but right now I’m far from knowing anything useful about PHP or PHP books other than that.