Instructions includ, require and readfile

Instructions include, require and readfile

There are two instructions that allow you to switch to the code contents of another file also contains PHP code. Both of these instructions is given one parameter – the name of the file to include in the code (it can be the path to a file located on another web server). The difference between them is how to enable these files to the code. For instructions „require” the files are attached to the code before parsing, in every place where there is an instruction „require”.


Therefore, this manual is not suitable for attaching the file whose name is taken from the variable – instead, use the „include” statement. Using these instructions should be aware of two things. First, the processing of files using the include begins with HTML mode, so if the file contains only PHP code, it should start with one of the tag opening. Second, keep in mind that if you include instruction is used in a loop or conditional statement, despite that this is one line, this must be it in braces, because this single line is converted into multiple lines attached with another file. Second, keep in mind that if you include instruction is used in a loop or conditional statement, despite that this is one line, this must be it in braces, because this single line is converted into multiple lines attached with another file.

The readfile ()

Another type of function used to attach the content of another file function readfile (). The thing that distinguishes this function from the instructions in the previous paragraph is that the data downloaded from the file are not processed by PHP, so this function is only suitable for displaying HTML or plain-text.

Cookies help us deliver our services. By using our services, you agree to our use of cookies. More Info | Close