Running CGI Scripts and
Executing Programs
From Your
Server Side Include Enabled Pages
One of the greatest things about using server side includes
is the ability to either run programs as straight system
executions, or as CGI Scripts. For security reasons, most
servers are now configured to only use the Virtual
method instead of the Exec method.
The primary differences between the two methods are:
Exec scripts do not inherit all that great CGI
Server/Client information that Virtual does.
Virtual scripts must be in a directory
from which you can run CGI scripts.
Personally, I strongly recommend that you employ the Virtual
method. For purposes of completeness, both are presented here.
THE EXEC SSI
My sincerest apologies to my readers using non-graphical
browsers for what follows next...
BigNoseBird.Com Says Today is Apr 26, 2018
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
The calendar above was done using a small PERL program and what
is called an exec cgi. We will be exploring this method
soon, so stay tuned...
If you are really impatient then here is the idea... Take the
line of code below and place it your HTML document where you
want to place the calendar.
<!--#exec cmd="./calprog.cgi" -->
Now, download
calprog.cgi and place in it the same directory that your
HTML document is in. Make sure that the line:
#!/usr/bin/perl
Is the very first line in the script with no blank line above it!
After installing the script issue the command:
chmod 755 calprog.cgi
To test the program, at your prompt, enter the command:
./calprog.cgi
You should see a bunch of HTML code go by. If you only get
the names of the days, check the program for the path to your
Unix cal program. If it does not run at all, recheck your
chmod 755 calprog.cgi and the path to perl in the
program.
There are two potential problems. The first is that some systems
require that executable programs for use with SSI reside in a
special directory. The other is that they may have to end with
the extension .cgi Some systems also forbid this type
of program for security reasons. If so, please take a look at
the next section which deals with calling cgi-bin programs
using SSI.
If you cannot get this program to run, see if your system has
a FAQ on where to place executables for use with SSI.
The INCLUDE VIRTUAL SSI
Many servers do not allow the EXEC SSI to be used. If
this is the situation at your site, this is probably a good way
around this restriction.
In our calprog.cgi example above, we are running a small
program that returns HTML text back to the browser. Using the
code below, it is possible to run the include from our
CGI directory.
<!--#include virtual="/cgi-bin/calprog.cgi" -->
It is also very important to make a minor change to our
program. Since we are using CGI, we must tell the browser what
exactly is being returned to it. This is accomplished by starting
our programs output with:
print "content-type: text/html\n\n"
The other major difference from the EXEC is that you give
a URL such as:
/cgi-bin/calprog.cgi
Even better, you can pass information via the QUERY_STRING to your
script like this:
/cgi-bin/calprog.cgi?name=joe&id=12385
This combination of SSI and CGI is ideal for applications such as
banner rotation programs and counter scripts.