Free Web Hosting by Netfirms
Web Hosting by Netfirms | Free Domain Names by Netfirms

[ . ]
 
[ Web Magic ]

Server Side Includes

[ line ]

Some servers provide you with the ability to embed server commands into your HTML documents in the form of special HTML tags. When the server processes your document, it will replace these server commands with text appropriate to the function of the tag. This allows you to insert server environment variables such as the server hostname, client address, or hit count.

Server Side Includes (SSI) also allows you to insert the contents of an entire separate file, or even the output from a CGI application or script.

The exec command is the most powerful of the Your Server SSI commands. It allows you to run a CGI application or plug-in and insert its results into the current document. You could also run multiple CGI applications or plug-ins from a single URL. There is no limit to the number of exec calls that you can make in a single document. The syntax is: <!--#exec virtual="/cgi-bin/mycgi.cgi"-->

<!--#exec cgi="counter.cgi"-->
<!--#exec cmd="counter.cgi "-->

The include command allows you to include the contents of a file into the current document. This is particularly useful for including common parts of documents that are identical across multiple documents. For example, say all of your site's pages have a common footer that contains a button bar with links to other documents on your site. If the URL of one of these linked documents changed, you would have to update every document on your site to point to the new URL. An easier way is to use the include command.

The include command takes one argument, which can be either a "virtual" or "file" argument. If the include command is unable to find the file to be included, it will strip the command from the output text, but will not replace it with anything.

<!--#include virtual=" "-->
<!--#include file=" "-->

The echo command allows you to insert text into your HTML document. When Your Server encounters the echo command, it replaces the command with the specified value.

<!--#echo var="(different variables for this one)"--> - See Environment Settings below:


Making a Real Back Button

Here is a cute server side include trick, a back button that actually takes you back to where you came from.

<A HREF="<!--#echo var="HTTP_REFERER"-->">BACK BUTTON</A>

If you came to this page directly, such as from a link in your e-mail or you hand-typed it in, then (none) would be the value for HTTP_REFERER.


Displaying current Date and Time within cgi scripts

Shows how to create a file and subroutine which will allow you to include SSI within your scripts. Specifically using DATE_LOCAL to display current date and time.

This subroutine can be easily modified to include files within scripts.


CGI Environment Settings

These are variables that are set every time a CGI script is run. They are defined by both the server and client. Depending on the server and the context, they may or may not all be set.

ACCEPT_LANGUAGEThe human languages that are acceptable to the remote client.
AUTH_TYPEThe authentication method used to validate the remote client.
CONTENT_LENGTHThe length of the attached information in the case of a POST or PUT.
CONTENT_TYPEThe content type of the attached information in the case of a POST or PUT.
DATE_GMTThe current Greenwich Mean Time, with format specified by the config command.
DATE_LOCALThe current date, with format specified by the config command.
DOCUMENT_NAMEThe name of the document requested
DOCUMENT_URIThe URL of the document requested
FORWARDEDThe name of the proxy server through which this document is being processed.
GATEWAY_INTERFACEThe name/version of the Common Gateway Interface served on this HTTP server.
HTTP_ACCEPTA comma separated list of mime types that are accepted by the remote browser.
HTTP_COOKIEThe cookie sent by the remote client.
HTTP_REFERRERThe URL of the page that the client followed to get to the current document.
HTTP_USER_AGENTThe browser the client is using to send the request.
LAST_MODIFIEDThe date and time of the current document's last modification, with format specified by the config command. i.e. <!--#flastmod file="ssi.shtml" -->
PAGE_COUNTNumber of accesses to current document since server was brought on line.
QUERY_STRINGThe raw query string sent from the remote browser.
QUERY_STRING_UNESCAPEDThe unescaped query string sent by the client browser, all shell-special characters escaped with \.
REMOTE_ADDRThe IP address of the client
REMOTE_HOSTThe domain name of the client, if the Use DNS option is set.
REMOTE_IDENTThe remote user name if supporting RFC931 identification.
REQUEST_METHODThe method by which the current document was requested.
REMOTE_USERThe user name used to validate authentication from the remote client. Great for use in password protected sites.
SCRIPT_NAMEThe virtual path of the script being executed.
SERVER_NAMEThe hostname of your server, such as "www.yoursite.com".
SERVER_PORTThe IP port the HTTP server is answering on.
SERVER_PROTOCOLThe protocol implemented by the server, "HTTP/1.0"
SERVER_SOFTWAREThe name of the server application, "Your Server"
TOTAL_HITSTotal pages served by server since brought on line.

How to access them: this differs between languages. In Perl, they are stored in the %ENV hash, with the name of the environment setting being the key value in the hash. For example, to print the remote host of the visitor, do this:

      print "Remote host: $ENV{'REMOTE_HOST'}.\n";

This Perl / CGI script will print out the all the keynames and their values that are set:

#!/usr/bin/perl

print "Content-Type: text/html\n\n";
print "<table>\n";
 foreach $key (sort keys %ENV)
 {
print qq|
<tr><th align="right">$key:</th><td>$ENV{$key}</td></tr>\n
|;
 }
print "</table>\n";

Remember to use these settings with respect for others and their privacy :)

[ line ]

[ Back to Top | Home ]

Free Web Hosting by Netfirms
Web Hosting by Netfirms | Free Domain Names by Netfirms

[ Creative Computing ]

[ Recommend Our Site ]     [ Creative Computing ]     [ HTML 3.2 Validated ]

Copy & Copyright (c) 1998 - 2006   Creative Computing

Free Web Hosting by Netfirms
Web Hosting by Netfirms | Free Domain Names by Netfirms

Please Click To Visit Our Friends At:
Home

Free Web Hosting by Netfirms
Web Hosting by Netfirms | Free Domain Names by Netfirms

HTML Tips
HTML Validation
CGI Tips
Web Security
Search Engines
Spam Mail

Online Services
META Tag
    Generator

Web Whois

Site Resources
Site Links
Earn Cash

DBMan FAQ

Creative Computing

Contact
Guest Book

[ Recommend ]

[ Site Map ]

    [ Cross ]

[ Creative's Health News ]

[.]