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 |
Category: | Basics |
Level: | Beginner |
Product: | See complete product |
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:
- index.php
- header.php
- footer.php
- menu.php
- content.php
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:
- include
- require
- include_once
- require_once
Next Step of PHP include file
Tags: php incluude file, php include, include file, file include, php, include, file
<Back - Tutorial Index Next - Step 2> -->PHP include file - Table of contents |
---|
Step 1 - Include files introduction |
Step 2 - The php include function |
Step 3 - Include file more than once |
Step 4 - The php require function |
Step 5 - Include files only once |