PHP Tutorials

XMLStyleSoldierFlowerMonkey

Include/SSI

Learn how to use the include() function using the power of PHP.

Spreadshirt
Overview
One of the most important and essential functions used in PHP is the include() function. The include() function lets you call an external file from your server, There are several key factors why it is rated much higher than SSI. Not only is it faster, but it burns much less CPU usage than SSI. You can keep the extension (*.php) and not have to rename it to some other extension (like *.shtml). You can call any type of file including other PHP, HTML, SHTML, CGI, etc using the include() or virtual() functions.

How do I use it?
Well if you want to call a PHP or HTML file and its located in the same directory, then all you have to say is:
<? include ("thefile.html") ?>
Another nice feature about the include() function is the fact that you can use the absolute URL of the file you're trying to fetch. For example, say you own two different sites under two completely different domains and servers, but you want to share a common file, then all you have to do is write:
<? include ("http://www.whateverurl.com/thefile.html") ?>
What about CGI/SSI and SHTML Files?
Well, PHP is one smart language. You can use the virtual() function to run anything that you would parse through Apache. For you beginning web developers who that want that in English, it means that you can use virtual() to run CGI and Perl in a PHP file. The following two accomplish the same thing:
<!-- #include "whatever.cgi" -->

<? virtual ("whatever.cgi") ?>
Beware that the virtual() function is not as fast and efficient as the include() function because it goes to Apache, but none the less its available.

Conclusion
Well if there's one thing we can conclude from all this, then its one thing: PHP was a thought out language which can do a myriad of things quickly and efficiently. Simply states, it kicks all other *nix Server Side Languages out of the water.

Discuss this tutorial »
Written by: Akash Goel
Back to PHP TutorialsTop


Copyright © 2000-2008 Spoono, LLC. All rights reserved.
Network: Reseller Web Hosting by Spoono Host | Spoonloads | Absolute Cross
Terms of Service | Privacy Policy.

kdfj