View your IP Address: (none)♦MembersHelpBookmarkNewHOT110mbAlexa Ranking

Vietnamese | English

StudyInfoTechSecurityEntertainmentTourismCareerSocialBusinessScience
World Times♦Vietnam:
♦California-USA:

Include Command of SSI



Products / Services

The purpose of this quick guide is to show you how to include a file into another file using SSI. In order to include a file you must use the INCLUDE command!

The include command inserts the contents of a specified file into the response stream being sent to the client replacing the include directive. There are two kinds of includes:

Include File:

The file element is used with files which relative to the folder of the current document. In other words, the file which we want to include is in the same directory as the file which contains the include command or in a directory below the file. You can not use 'File' to go "up" a directory such as "../include-this.htm"

For instance:
<!--#include file="copyright.txt" -->
or
<!--#include file="includes/copyright.txt" -->

Include Virtual

The virtual element represents paths that are relative to the base folder of the Web server. In other words, virtual element should be used when the path to the document is given relative to the document root.

For instance:
<!--#include file="/copyright.txt" -->
or
<!--#include file="/includes/copyright.txt" -->

File Extensions of Included Files

The file to include can generally have any extension: .txt, .htm, .html, .inc, etc... If the document to be included contains SSI code which will need to be parsed by the server then it will have to have the extension .shtml or whatever your server is set-up to parse (process).

Unless you're executing a cgi script, you should always use "include". It's faster and safer.

Include other document via Ajax script

You can also use Ajax script below (DHTML interacting with the server) to let you include the contents of an external page onto the current document dynamically.

Step 1: Insert the below script to the HEAD section of your page:

<script type="text/javascript">
<!--
var rootdomain="http://"+window.location.hostname;
function ajaxinclude(url) {
var page_request = false;
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest();
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP");
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){}
}
}
else
return false;
page_request.open('GET', url, false); //get page synchronously 
page_request.send(null);
writecontent(page_request);
}
function writecontent(page_request){
if (window.location.href.indexOf("http")==-1 || page_request.status==200)
document.write(page_request.responseText);
}
//-->
</script>

Note: Included file MUST be from the same domain as the page displaying it.

Step 2: Once that's done, to include an external page, simply use the below code in the BODY section of the master page where you want its contents to be shown:

<script type="text/javascript">
<!--
ajaxinclude("sample.html")
//-->
</script>

This will cause the script to retrieve "sample.html" and display its content on the page. You can call the above multiple times with different file names to include multiple files. Note that the included file MUST be from the same domain as the page including it due to security limitations with this feature.

You can also include the file by specifying the full URL to it on your server, such as:

<script type="text/javascript">
<!--
ajaxinclude(rootdomain+"/includes/sample.html")
//-->
</script>

"/includes/sample.html" is the path to your external file MINUS your domain name itself (ie: http://esiportal.110mb.com). Do not specify your domain, as the script will detect that by itself via the variable "rootdomain." Again, the limitation with both the included file and master page being on the same domain applies.

View more... 
Select Vietnamese to find other information or service from Vietnamese site(s).

Email to your friendEmail to usGet updates by EmailView updates on WebFollow us on TwitterGoogle Safe BrowsingMcAfee SiteAdvisorDiagnostic this pageNoreton SafeWebDrWebTechnorati LinksSave to del.icio.usAdd to del.icio.usDigg This!Share on Facebookoutside.in: geotag this storyDiscuss on NewsvineStumble It!Add to Mixx!

If you would like to submit your website for FREE or advertise your own webpage(s) on our webpages, please enter Terms of Service webpage to send your request. Thank you!

©2004- ESI Portal ™®

Products / Services

(\__/)
(=^.^=)
(")_(")
ESI Portal
HOME
Top News
Online Tools
Online Translator
WYSIWYG Editor
Source Code Editor
Real Time Tool
2D Map Tool
3D Map Tool
Forex News
Online Shopping
Watch Videos
Listen Songs
Find Jobs
For Webmasters
About Us
Privacy Policy
Terms of Service
Contact Us
Live chat with us