From the course: Learning PHP

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Using include and require

Using include and require - PHP Tutorial

From the course: Learning PHP

Start my 1-month free trial

Using include and require

- [Instructor] There are two ways to include external files in PHP. They are with the built-in directives or functions, Include and Require. There is a small distinction made because Include and Require don't have the parentheses around them, though you could write them that way. They're not technically functions. They're more like statements that you're making. They both work the same way though, with the small difference that with Include, if the file doesn't exist, Include will throw a warning or non-terminating error, and Require we'll throw a compile error, which will stop the program from running. So let's say that we have two files, Index and Variables, both are in the same directory. What we can do is copy the variables from Index and paste them into the Variables dot PHP file. We still need the opening PHP tag here, and then we'll save that. And instead, we could say Require will require this because our…

Contents