Our Blog - PHP Include Function
If you want to include same codes on multiple pages, you can use PHP Include Function. To use this function, you have to name the extention of your web file as PHP (eg - contact.php). You can write the common codes in one file and create a connection with other files.

After writing the common codes inside a seperate file (Common Name : Include File), you can write this line inside a target page.

< ? php include (' ') ?>

You must define the file path inside the brackets. For example,

< ? php include(' includes/navigation.php ') ?>

As a result of this, these codes will display inside the relevant files.

If you use the same code in 100 files, you have to edit 100 files one by one. But if you use this function in 100 files, you have to edit only 1 file. Because you have already connected that file with other 100 files. This function can save lot of time. Furthermore there is no repetition in same codings, it helps to reduce the file size.

Think you have accidentally placed the same Include file two or three times in same web page. Then the web page will show same codes or elements in multiple places. You can use Include Once function to prevent that.

< ? php include_once (' includes/navigation.php ') ?>

As a result of this function, the web page will load only one function.

Furthermore there are two other functions called Require function and Require Once function. These functions also do the same operation. But there is only one difference. Click Here to learn !

By : Danula Randika Wickramaarachchi
From : Sri Lanka
Published Date : 2017.02.10

Thanks for reading. Leave a comment to let us know what you think...