Start New Discussion within our Web Development Community

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.

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.

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

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

This article has been dead for over six months. Start a new discussion instead.