PHP Include , Require , Include Once (include_once) and Require Once (require_once)

PHP Include and Require

Include and Require

If you need to separate a file into many part and then want to marge them into one php file then you need to use php include,

and they are:

1. include
2. include_once
3. require
4. require_once

PHP include

This is used while needed to include a file into another file ,
** Include a file can be used many time in a page or file.

Example

<?php
include(‘header.php’); // or include can be written as include ‘header.php’;
echo “Its the body part”;
include(‘footer.php’);
?>

PHP Include Once (include_once)

If a file needed to include in a file only for single time then include once is used, like functions page
** Include a file can be used to include a file only one time in a page or file.

Example (include_once)

<?php
include_once(‘function.php’);
echo “Perform the codding activity”;
?>

PHP require

while a file is required to execute a code then php require function is used, if the file not get then the function will not let execute the code

<?php
require(‘db_function.php’);
echo “Perform the database activity”;
?>

PHP Require Once (include_once)

If a file needed to include in a file only for single time and the file is required to execute the code then require once is used, like connection page.

Example (include_once)

<?php
require_once(‘connection.php’);
echo “Perform the database activity”;
?>

I wish you get a clear view on PHP Include , Require , Include Once (include_once) and Require Once (require_once)

Thanks for Reading

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.