We accept safe and secure Credit Card and PayPal Payments.
 
Perl Scripts

All Count
Attachment Mailer
Perl Scripts Build A FAQ Plus
Perl Scripts Clock In Center
eBackup Automated
Easy Poll
eSurvey
Fetch a File
Form Maker
Mailing List Server
MySQL Mate
PDF Creation
QCart
Quick Fix
Quote of the day
Speed Search
Task Manager
Traffic Pack
Upload Plus
Upload Gold
Upload Pro
Website Manager

 
Free Perl Downloads

Free Perl Scripts Main Page
Free Perl Scripts 404 Alerter
AccessLog Viewer
Build A FAQ
PHP Scripts eBackup
Free PHP Scripts ErrorLog Viewer
eVars - Server Info
HT Pass Creator
Upload Lite
Website Manager

 
JavaScripts

Free Java Scripts Alert Boxes
Free JavaScripts Browser Sniffer
Check email
Generators
Slide Show
Sudoku
Window Maker
More...

 
Extra Utilities

ASP Scripts Ascii Codes
Free ASP Scripts Color Picker
Font Finder
HT Pass Creator
Meta Cloak
Meta Magic
Pano Zooms
SlideShow
Server Size

 
Online Tutorials

Free HTML Scripts Glossary
Free HTML Scripts HTML
JavaScript
MySQL
SSI
Build Traffic
Other

 
Miscellaneous

About Us
Graphics
Testimonials
Installations
Latest versions

 
Hawk Eye in Tennis

Should Hawk Eye replace linesmen and lineswomen at all tennis tournaments?







 
View all Polls

Run Polls on your site

Run your own Surveys

 
Store Download FAQs Contact Us Support Programming Policies  
Server Side Includes

To a webmaster, Server Side Includes are bliss. Website Manager is an SSI manager. SSI allows you to include a text file in an unlimited number of web pages. So when it comes time to update all those web pages, you can make the change by editing just the one text file. You will need to ensure your server supports SSI. If your server is a unix/linux server, you can be pretty sure it supports SSI. SI requires the use of Apache Server software. Most unix/linux server use Apache. Some Windows server also use Apache, but most of them use IIS (Internet Information Server). The server software is not something you can change, and because it runs th entire server (including other people's web sites) your host will also refuse to change it for you. They may instead be kind enough to move your site to anther one of their servers which does use Apache.

Most people will tell you that to use SSI, you must name the page with a "shtml" extension. While that may be the case initially, you can set the server to also accept and parse regular "htm" or "html" files. The draw back is that each time any page is called, it will be first examined to see if parsing is neccessary. This usually takes an extra millionth of a second. Parsing means the server reads the structure of a file prior to serving it, to determine whether any dynamic content is required.

SSI Basics

The most common use for SSI is to include files which allow for site wide updates. To achieve this, you need to add an SSI command to each of your web pages. The command tells the page where to find the file that should be included. You may have noticed that our menu (on the left) is precisely the same across our entire web site. That's because it uses SSI. Here is the simple command :

<!--#include virtual="/header.txt" -->

We have placed something similar to the above command in everyone of our web pages. Each time someone request one of our web pages, it tells the web server to fetch the contents on a file named "header.txt" and include in the web page. The contents of "header.txt" are placed exactly where the SSI command is. The preceding slash "/" tells the server that the "header.txt" file is located in the web directory (the same directory that houses the home page). You can also call includes from other directories, by entering the correct path from the web directory or a relative path. For example, if your files to be included where in a folder named "includes" which was a folder in the web directory, you would use something like the following :

<!--#include virtual="/includes/header.txt" -->

You can add that command to any number of your web pages. Each page would then print the contents of "header.txt" into itself. Then, when you changed the content of "header.txt" all pages that use the above SSI command would also be updated. Imagine the time you would save if you had 1,000 web pages and need to correct a spelling mistake, or add a new link to your menu.

Allowing HTM and HTML files to be parsed

Somewhere on your server there may be a file named ".htaccess". Files that begin with a period, are usually hidden from view when you FTP in to your server. If you can't see one in your web folder, it's either because it's located above the web folder or your FTP client doesn't show them. Most FTP clients can be set to show all files. WS_FTP makes it real easy. Cute FTP is a little confusing as it seems to show the entire web site and all of it's folders and files in one screen. To view all files using WS_FTP, from the top menu bar select :

Sites -> Organize sites -> Right click on site name -> Properties -> Start up Tab

In the "Remote file mask" text box enter "-al". That's "dash A L" without quotes. That's a unix command for "list all files". Now see if you can find a .htaccess file. If you cannot, it's safe to create your own. If you're using .htaccess to protect web directories or for custom error pages, it pays to first find out where the .htaccess files are located to ensure you do not overwrite directives contained within them.

To create your own ".htaccess" file enter the following :

AddType text/html .shtml .shtm .htm .html
AddHandler server-parsed .shtml .shtm .htm .html


If you'd like to use your own custom error pages, you may also enter :

ErrorDocument 401 /auth.html
ErrorDocument 404 /missing.html
ErrorDocument 405 /invalid_method.html
ErrorDocument 500 /server.html


Save the file and upload it to your web folder (the folder that contains your home page). If you used the custom error page directives, you need to create those files also (missing.html etc) and upload them to your web folder. So, for example, when a page cannot be found, (404 error), the user will be directed to "missing.html" where you can present them with links to your home page or instructions on what course they can take next.

The Handler directives tell the server to parse .shtml, .shtm, .htm and .html files. You should now be able to add SSI commands to any of those types of files. These handler directives are usually stored in the server's config file (httpd.conf).

Advanced SSI

SSI is an advanced language with many commands and statements available. I will cover a small portion of them here. First thing to note is that the comment terminator (-->) should be preceded by a space to ensure it's not treated as SSI syntax.

As stated above, in SSI Basics, you can use the "include" command to include files. You can also use the "exec" command to execute regular cgi scripts. It can also include files, but unless you're executing a cgi script, you should always use "include". It's faster and safer. For example,

<!--#exec cgi="/includes/test.cgi" -->

would execute a cgi script named "test.cgi" which is located in your web folder. As with all cgi scripts, "test.cgi" should be CHMOD to 755 (or the correct execution permissions). The directory that contains the cgi script, must also be enabled for cgi scripts (your cgi-bin for example).

You can also use the "echo" command to dynamically print content such as dates and variables :

The current date in Greenwich Mean Time
<!--#echo var="DATE_GMT" -->
Saturday, 21-Dec-2024 12:14:31 GMT

The current date in the local (server's) time zone
<!--#echo var="DATE_LOCAL" -->
Saturday, 21-Dec-2024 07:14:31 EST

The name of the current document
<!--#echo var="DOCUMENT_NAME" -->
ssi.html

The (web) path and name of the current document
<!--#echo var="DOCUMENT_URI" -->
/tutorials/howto/ssi.html

The date the current document was last modified
<!--#echo var="LAST_MODIFIED" -->
Sunday, 22-Jul-2012 04:05:40 EDT

The browser type
<!--#echo var="HTTP_USER_AGENT" -->
Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)

The remote host (yours)
<!--#echo var="REMOTE_HOST" -->
(none)

The IP address (yours)
<!--#echo var="REMOTE_ADDR" -->
18.119.143.201

The request method (GET, PUT or POST)
<!--#echo var="REQUEST_METHOD" -->
GET

Some other variables you can experiment with are :

DATE_LOCAL
DATE_GMT
DOCUMENT_NAME
DOCUMENT_PATH_INFO
DOCUMENT_ROOT
DOCUMENT_URI
GATEWAY_INTERFACE
HTTP_ACCEPT
HTTP_ACCEPT_ENCODING
HTTP_ACCEPT_LANGUAGE
HTTP_CACHE_CONTROL
HTTP_HOST
HTTP_IF_MODIFIED_SINCE
HTTP_REFERER
HTTP_USER_AGENT
HTTP_X_FORWARDED_FOR
LAST_MODIFIED
PATH
QUERY_STRING
REMOTE_ADDR
REMOTE_PORT
REQUEST_METHOD
REQUEST_URI
SCRIPT_FILENAME
SCRIPT_NAME
SCRIPT_URI
SCRIPT_URL
SERVER_ADDR
SERVER_ADMIN
SERVER_NAME
SERVER_PORT
SERVER_PROTOCOL
SERVER_SIGNATURE
SERVER_SOFTWARE
UNIQUE_ID
USER_NAME

or print the entire environment as returned by your server using :

<!--#printenv -->

You can also set variables (in Apache 1.2 and later), then conditionally display data, such as printing tags only if the browser is Internet Explorer.

<!--#set var="Agent" value="${HTTP_USER_AGENT}" -->

Print it

<!--#echo var="Agent" -->

Check the variable to see if it contains "MSIE", and if true, print today's date, else print some text that says it's not MSIE.

<!--#if expr="$Agent = /MSIE/" -->

<!--#echo var="DATE_GMT" -->

<!--#elif expr="$Agent != /MSIE/" -->

You are not using MSIE

<!--#endif -->

When testing expressions, the usual escape rules apply. For example, if you were looking to match a string the contains the dollar sign, you would need to escape the dollar sign with a backslash.

<!--#if expr="$a = \$" -->

To disambiguate variables that could be interpreted in more ways than one (because the dollar sign is not required in variables and may be treated as a string), you can use the dollar sign and braces as in :

<!--#set var="UserAgent" value="Your Browser is ${HTTP_USER_AGENT}" -->

The basic flow control for if,else conditions (available in Apache 1.2 and later) is as follows :

<!--#if expr="condition" -->
<!--#elif expr="condition" -->
<!--#else -->
<!--#endif -->

The if condition is evaluated and if true, then any text until between it and the next condition is printed to the web page. The elif or else conditions (both optional) are be used the print text text to the web page if the if was not met. The endif condition terminates the conditional block and is required.

Conditions have the following meanings and can use any of the following operators:

<!--#if expr="$Var" --> True if $Var has any value at all

<!--#if expr="$Var = hello" --> True if $Var equal "hello". Keep in mind, that if the string you're trying to match has a space, you must quote and escape the string as in

<!--#if expr="$Var = \"hello there\"" -->

or use single (nested) quotes without escapes. Note that if using single quotes, they must be nested within double quotes.

<!--#if expr="$Var != hello" --> True if $Var does not equal "hello"

<!--#if expr="$Var = /hello/" --> True if $Var contains "hello" anywhere within the entire value of the variable. Similar to Perl and Javascript regular expressions

<!--#if expr="$Var = /hello/ && $Var = /there/" --> True if $Var contains both "hello" and "there" anywhere within the entire value of the variable.

<!--#if expr="$Var = /hello/ || $Var = /there/" --> True if $Var contains "hello" or "there" anywhere within the entire value of the variable.

If you're familiar with Unix, Perl or JavaScript programming and regular expressions, feel free to experiment with other operators you're aware of such as parenthesis. There are many similarities in regular expression syntax that apply to these languages.

Speed Search our site
Plesk Hosting
Linux servers with Plesk Control Panel, cgi-bin, crontab manager, Mysql, PHP and ASP.

Linux Hosting Plans from $9.12 per month, includes Plesk Control Panel, MySQL databases, cgi-bin, crontab manager and 50 email accounts.

Discounted Scripts
Subscribe to our periodial newsletter to receive special offers.

Bathroom Hygiene
How often do you thoroughly clean your bathroom?








View all Polls

Run Polls just like this one on your website!


About us | Contact us | Script FAQs | Script Support | Website Hosting | Our Policies | Store | Testimonials
Subscribers log in here. Subscribe to our periodical newsletter for special offers on commercial scripts, hosting, exciting business opportunities, and industry news and events. Our Mailing List Software is powered by Consolidator    
HTML Plain text
©1999 - 2015 All content Copyright PerlScriptsJavaScripts.com Proudly hosted by LinuxHostingPlans.com