PHP include file

Home - Tutorials - Basics

In this tutorial I will show you how to divide your code into more files and how to include various files into your actual PHP code.

Tutorial info:

Name:PHP include file
Total steps:5

Bookmark PHP include file

Step 1 - Include files introduction

PHP include file

If you want to make a project then it is not a good idea to put all of the code into one file. Even a quite simple task can result a huge amount of code. To maintain and reuse a code from a single file is quite hard.

If you download and check the source code of any PHP project you will find a lot of files. Each file contains only a well defined task implementation. For example in OOP each class has it's own file or you create a file for DB management an other one for mail sending and an other to display menu system.

A real example could be a project with the following files:

The final page is constructed by using all of the above mentioned files. The benfit of this structure is that if you need to change meta information you only need to edit the header.php file and so you probably make less error.

However to make this sollution to work you need to learn how to include a file in an other one. There are more ways to do this in PHP. You can use the following functions:
In the next steps I will explain how to use them.

Next Step of PHP include file

Tags: php incluude file, php include, include file, file include, php, include, file

Follow phpf1 on Twitter

F1 Site Family
Java F1
JavaScript F1

Total time: 0.5144