1,105,592 Community Members

difference b/w include() and require() in php

Member Avatar
Junior Poster
131 posts since Feb 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]

Hi everyone,

I know this is very simple questions. But i want to know that in which case we use function include() and in which case we have to use function require() in php code.

Please help me.

Member Avatar
Occupation: Genius
3,028 posts since Sep 2007
Reputation Points: 387 [?]
Q&As Helped to Solve: 281 [?]
Skill Endorsements: 15 [?]
Team Colleague

Well they both are identical when it comes to physical use but the only difference is error reporting. If include() fails then a standard error will be displayed and the page will continue loading however, if require() fails then the entire script fails and the entire page comes to a stop with the error message.

Member Avatar
Posting Whiz
354 posts since May 2008
Reputation Points: 16 [?]
Q&As Helped to Solve: 31 [?]
Skill Endorsements: 0 [?]

Basicaly if you had a password protected page that called the script to validate the passwords like this:


and you accidental deleted validate_pass.php then any user could see your password protected page. However if you used require then the PHP script would not output the rest of the file.
Sam R

Member Avatar
Light Poster
28 posts since Mar 2009
Reputation Points: -1 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]

Hi this is nathen,
The include() function takes all the text in a specified file and copies it into the file that uses the include function.
The require() function is identical to include(), except that it handles errors differently.

The include() function generates a warning (but the script will continue execution) while the require() function generates a fatal error (and the script execution will stop after the error).

Further complete information you see http://www.w3schools.com/PHP/php_includes.asp

This article has been dead for over three months: Start a new discussion instead
Start New Discussion
Tags Related to this Article