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

Recommended Answers

All 3 Replies

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:

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.