|
This
is a brief introduction to using user CGI routines on the CSE systems.
We regret that we cannot give you extensive help with writing or debugging
your routines. Please consult one of the many HTML books for further
details. |
How
CGI Routines Work |
A
CGI routine is invoked using an HTML statement such as |
<!--#exec cgi="/cgi-bin/counter-ord"-->
|
in
an otherwise normal HTML file in your web directory. This statement
looks just like a comment, and it will be treated as a comment unless
you give the file containing this statement `execute' permission.
(Which is how we have chosen to tell our web server to look more closely
at a file it is serving, to see if there is something there for it
to do.) If the file is named mystuff.html, do this: |
|
The
example used above, by the way, is how you embed an access counter
in a web page at our site. A full example would be: |
Wow, like farmed out, dood, yours is the
<!--#exec cgi="/cgi-bin/counter-ord"-->
access to my page since I installed this counter,
which makes you one groovy frood!
|
(Notice
the way that is worded. This counter does not reliably count people,
it counts the number of times the server is asked for the page. So
one person may rack up several accesses as they bounce around your
pages.) |
The
/user/cgi Directory |
User
CGI routines must reside in a directory /user/cgi/<username>
where <username> is your login name. This directory is owned
by you, so you can create, modify, and remove files there at will.
The directory must remain world accessible (we create it that way,
with permissions 755), and the routines you place in the directory
must be world readable and executable (permissions 755). |
If
your username (login name) is knuth, then to invoke a routine in your
/user/cgi directory, do this: |
<!--#exec cgi="/cgi-user/knuth/whatever"-->
|
where
whatever is the shell script or binary executable you place in your
cgi-user directory. To invoke a routine via a link, do this: |
|
Note:
Your cgi directory is now created when your account is created. If
you have an old account and do not have a cgi-user directory, just
send email to manager@cse.msu.edu and we'll be happy to create a directory
for you -- but please check user/cgi BEFORE you request one be made
for you. |
Common
CGI Problems |
The
first two lines of output generated by your CGI routine tell the web
server how to interpret the rest of the output. The first line specifies
the content type, and the second line is empty. For most CGI routines
the first line of output should be: |
Content-type: text/html
|
This
tells the web server that the remaining output is HTML. Remember that
the second line must be empty. |
Any
output generated by your CGI routine that is sent to stdout is interpreted
by the web server and must be valid HTML. If the server gets confused,
it complains about a ``server error'', but what it is trying to tell
you is that it can't make sense out of what your CGI routine is generating. |
Check
that your web subdirectory, your HTML files, and your CGI routine
have the correct access permissions! |
As
a last resort you can look through the mounds of information in /user/web/logs/error_log
for clues. The following command is useful for finding errors. |
tail -f /user/web/logs/error_log
|
Run
this command, then activate your script, and watch what happens. Any
output sent to stderr by your script will appear in the error log. |