A CGI script is referred to using a URL like any HTML document. The difference is that CGI scripts normally need some parameters in its standard input, based on which they generate something meaningful (in HTML format) to their standard output. This input is usually generated by using a "front end" HTML page with an input form.
In its input form the "front end" HTML page specifies an action
to take when the client submits the input [for further processing].
E. g.:
<form name="PrimTextForm"
action="http://cosi-nms.sourceforge.net/cgi-bin/cgi_prim/cgi_prim.cgi"
method="Post">
or
<form name="PrimTextForm"
action="/cgi-bin/cgi_prim/cgi_prim.cgi"
method="Post">
How does the webserver understand that the CGI script needs to be executed rather
than displayed like a regular HTML page? CGI scripts reside in a special directory
("cgi-bin" in the above example). When a webserver receives a request for a
page from this directory it will not display it, but rather run it and send
back what the program printed to its standard output.
<html><head><title>CGI primer</title> <script language="JavaScript"> <!-- function ChkBlank(FormField) { if(FormField.value == "") { alert("The input field is empty"); return(false); } else { return(true); } } //--> </script> </head> <body><h1>CGI primer</h1> <h2>Cut'n'paste input</h2> <form name="PrimTextForm" action="http://cosi-nms.sourceforge.net/cgi-bin/cgi_prim/cgi_prim.cgi" method="Post" onSubmit="return ChkBlank(document.PrimTextForm.InText);"> <textarea name="InText" rows="5" cols="80"></textarea><br> <input type="reset" value="Reset"> <input type="submit" value="Analyse"> </form> <h2>Input by filename</h2> <form name="PrimFileForm" action="http://cosi-nms.sourceforge.net/cgi-bin/cgi_prim/cgi_prim.cgi" method="Post" enctype="multipart/form-data" onSubmit="return ChkBlank(document.PrimFileForm.InFile);"> <input type="file" name="InFile"> <input type="submit" value="Analyse"> </form> </body></html>
gdragon@sc8-pr-shell1:/home/groups/c/co/cosi-nms/cgi-bin/cgi_prim$ ls -al total 12 drwxr-sr-x 2 gdragon cosi-nms 4096 Mar 14 23:59 . drwxrwsr-x 4 dummy cosi-nms 4096 Mar 14 23:28 .. -rwxr-xr-x 1 gdragon cosi-nms 234 Mar 14 23:33 cgi_prim.cgi gdragon@sc8-pr-shell1:/home/groups/c/co/cosi-nms/cgi-bin/cgi_prim$cat cgi_prim.cgi #!/bin/sh echo Content-type: text/html echo echo "<html><head><title>CGI primer</title></head>" echo echo "<body><h1>CGI primer</h1>" echo "(" echo | date echo ")<hr>" echo "<pre>" cat echo "</pre>" echo "</body>" echo echo "</html>" gdragon@sc8-pr-shell1:/home/groups/c/co/cosi-nms/cgi-bin/cgi_prim$ echo "Test input string" | cgi_prim.cgi Content-type: text/html <html><head><title>CGI primer</title></head> <body><h1>CGI primer</h1> ( Sat Mar 15 02:06:06 PST 2003 )<hr> <pre> Test input string </pre> </body> </html> gdragon@sc8-pr-shell1:/home/groups/c/co/cosi-nms/cgi-bin/cgi_prim$See Example in action
* * * * ||* *|| || * * || |||| * * |||| ..:||||||:....:||||||:..
*If you would like to become a COSI developer, have questions, or need your group member permissions modified please contact Deborah