1.11M Members

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

 
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.
Thanks,
gagan

 
0
 

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.

 
0
 

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

include('validate_pass.php');

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.
HTH
Sam R

 
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

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