---
title: "Include and Require function in PHP"  
description: "Before discussing about include () and require () function in PHP first we will described what is Server Side Includes (SSI)? Server Side Includes (SS"  
author: "Anonymous User"  
published: 2011-09-20  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/236/include-and-require-function-in-php  
category: "php"  
tags: ["php"]  
reading_time: 2 minutes  

---

# Include and Require function in PHP

Before discussing about include () and require () [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) in PHP first we will described what is [Server Side](https://www.mindstick.com/forum/318/how-to-call-javascript-fuction-in-server-side) Includes (SSI)? Server Side Includes (SSI) is an [efficient](https://www.mindstick.com/articles/33637/three-tips-for-an-energy-efficient-home-for-2019) way through which we can insert all [content of one](https://www.mindstick.com/forum/118/problem-in-display-content-of-one-page-to-another-page) PHP file to another PHP file before the server executes it, with include() or require() function.\

The two [functions](https://www.mindstick.com/forum/160140/explain-the-role-of-functions-as-a-service-faas-in-serverless-computing) are identical in every way, except how they [handle errors](https://www.mindstick.com/forum/157886/how-do-you-handle-errors-and-exceptions-in-angularjs-applications):

· include() generates a warning, but the script will continue [execution](https://www.mindstick.com/blog/178/synchronous-and-asynchronous-command-execution-in-c-sharp-dot-net)

· require() generates a [fatal error](https://answers.mindstick.com/qa/94996/how-do-i-fix-a-fatal-error-in-windows-10), and the script will stop

These two functions are used to create functions, headers, footers, or [elements](https://www.mindstick.com/forum/1440/wpf-button-with-multiple-text-elements) that will be reused on [multiple](https://www.mindstick.com/blog/12797/iowa-is-expected-to-see-heavy-growth-in-multiple-sectors) pages.

##### include () function:

include () function takes all the content in a specified file and includes it in the current file. If an error occurs, include () function generates a warning, but the script will continue execution.

##### Example:

```
<?php   //Include all content of Master page   include ("MasterPage.php"); ?>
```

##### require () function :

require () function works same as include function except when an error occurs in the script then script will be stoped immediately.

You can differentiate these two by following example:

```
<?php  // Include wrong file(i.e does not exist) with include function    include 'Temporary.php'.'</br>';// display a message after including 'Temporary.php' file    echo '</br>'.'Message: Temporary file included'; ?><?php     // Include wrong file(i.e does not exist) with require function    require 'Temporary.php'.'</br>';    // display a message after including 'Temporary.php' file  echo '</br>'.'Message: Temporary file included';?>
```

---

Original Source: https://www.mindstick.com/blog/236/include-and-require-function-in-php

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
