Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

include, require, or virtual 1

Status
Not open for further replies.

Hokey

MIS
Oct 28, 2000
178
US
If you want to include a HTML header and footer in a group of php scripts .... what is the best way to do so.

I have a static html header called header.inc and a html footer called footer.inc. Every php script in this group calles the header.inc -- then displays the dynamic information requested from the database -- then calles footer.inc.

Calling those files with include, require, or virtual works, but what is the difference ... or is one better than the next for this application?
 
include() and require() are almost identical, being the PHP method to include a file into the active script, but virtual() is different in that it is not a PHP method, but simply a PHP request to Apache to perform a SSI include--meaning it's Apache that does the parsing, not PHP.

I recommend not using virtual() unless you have a specific reason to. The main reason to use virtual() is if you have to include some data from an existing CGI script or some other Apache function, where you need the script to be parsed by Apache, not PHP. (that also means you cannot include a .php file using virtual(I))
Virtual() can be used just to include static HTML, but I think Apache SSI's have higher overhead and less flexibility than the PHP include methods.

You will find your system to be more responsive if you use the PHP methods. To decide which one you want, you should read which will tell you the difference between require and include.

Also, with include() or require() you can even include a file from another webserver. (cool feature)
 
Thanks much! Some of the files might change depending on conditional statements ... so it looks like I will be using include().
(Guess it helps to read the manual -- now dont I feel dumb)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top