CGI script represents the program started by a demon httpd, carrying out some actions and returning data to a demon
httpd for transfer to their user to a browser. CGI script is a sluice (as follows from name Common Gateway Interface).
CGI in interaction with such applied systems as Data Base, spreadsheets and systems of processing of the graphic information
are returned to the user with the answer to its inquiry in the form of HTML-page, pictures or other means of representation
of the information.
Usually CGI script receives from a demon httpd the information through variable environments. Returns script this
information through a standard conclusion.
Variable environments:
- GATEWAY_INTERFACE - Specification CGI
- SERVER_NAME - the Name of a server
- SERVER_ADMIN - e-mail the manager
- SERVER_SOFTWARE - the Name and the version of a server
- SERVER_PROTOCOL - the Version of report HTTP or HTTPS
- SERVER_PORT - Number of port
- REQUEST_METHOD - the Method (GET or POST)
- PATH_INFO - the Additional information script (way)
- SCRIPT_NAME - name of script
- SCRIPT_FILENAME - the Full way to script
- QUERY_STRING - the Line of data at method GET
- REMOTE_HOST - the PC of the client
- REMOTE_ADDR - the IP-address of the client
- AUTH_TYPE - Type of autentification
- REMOTE_USER - the Name of the user
- CONTENT_TYPE - the Coding of data from the form
- CONTENT_LENGTH - the Size of the attached data
- PATH_TRANSLATED - the Converted version of a way
- HTTP_USER_AGENT - a browser of the client
- HTTP_REFERER - ULR the previous page
- HTTP_PROXY_CONNECTION - Connection through proxy
- HTTP_IF_MODIFIED_SINCE - If the document has been changed
- HTTP_HOST - DNS a name of a host
- HTTP_FROM - the E-mail address of the user
- HTTP_COOKIE - Cookie a browser
- HTTP_CONNECTION - Type of the established communication
- HTTP_ACCEPT - the List of accepted mime-types
Inquiries on method GET
At inquiry on method GET the body of inquiry is transferred in a command line of script. All body of inquiry is
transferred in a variable of environment QUERY_STRING, type of data of inquiry in CONTENT_TYPE, length in
CONTENT_LENGTH.
Inquiries on method POST
At inquiry on method POST the body of inquiry is transferred in a standard stream of input of script, type of data of
inquiry in CONTENT_TYPE, length in CONTENT_LENGTH.
The answer to inquiry
Script sends the answer to inquiry in a standard stream of a conclusion. The answer represents or the data generated of
script, or their site. The conclusion should begin with heading which consists of one of following fields:
1. Content-type - represents MIME-type of returned data.
2. Location is a field it is used in case data and the reference to them come back not. Represents URL.
3. Status - it is used for the task to a server http lines-statuses. Represents 3 digital code of the status, then
through a blank a line of the reason. For example - 404 Not Found.
Then, in the empty line consisting only from a symbol of carry of a line, the body of the answer follows.
Call of script
Script it is possible to cause in several ways. We shall stop on three of them:
1. On URL - by means of tag A HREF, by means of attribute ACTION of tag FORM, directly to set url in a browser.
2. By means of exec cgi - in a body causing script HTML the document the comment of such kind is located:
<!--#exec cgi "http://www.somesite.com/cgi-bin/somescript.cgi"->
Or
<!--#include virtual = "http://www.somesite.com/cgi-bin/somescript.cgi"->
In this case script necessarily should return the HTML-document, the conclusion begins with http-heading, then the
HTML-document which is not containing tags HTML and BODY follows.
3. By means of tag IMG SRC - in this case script should return the image. I.e. all over again the http-heading containing " Content-type: image/gif " or " Content-type: image/jpg ", and then the maintenance of a picture in the chosen format.
Processing of forms
Tag FORM has following syntax:
<FORM ACTION = "url" METHOD = " POST | GET " ENCTYPE = "application/x-www-form-urlencoded">
<INPUT | SELECT | TEXTAREA.....>
....................
</FORM>
Where url can be URL'îì scriptà, a command "mailto:". METHOD - the type of inquiry, ENCTYPE is applied only for
METHOD = "POST" and has only one value - application/x-www-form-urlencoded.
Tag INPUT creates on the form of a field of input of the information of various type. The tag has following syntax:
<INPUT TYPE = "type" NAME = "name" VALUE = "value.....">
Tag INPUT attributes:
1. TYPE - type of an element:
- hidden - the user does not see this element, but its value is transferred scriptó;
- image - a picture on which it is possible to click;
- text - an one-line field of input of the text;
- password - the field of input of the password, entered symbols are represented in the form of asterisks;
- checkbox - the button-switch, by pressing on which varies its value on "on" or "off";
- radio - the button-switch which as well as previous can have values "on" or "off", difference from previous that if one
of such buttons on the form matters "on", all other buttons of the same type and with the same parameter NAME, should
matter "off." (not too heaped up definition? ;) Both I understand - and I describe;
- submit - the button, by pressing on which the given forms are transferred to script;
- reset - the button establishing in all fields of the form of value by default.
2. NAME - a name of a field.
3. VALUE - initial value of a field.
For buttons of type radio and checkbox - "on" or "off". For buttons of type "submit" and "reset" is an inscription
on the button. We shall not consider other attributes INPUT. They are not so important for work of script.
Tag SELECT creates the dropping out menu on the form. The tag has following syntax:
<SELECT NAME = "name">
<OPTION> Option1
<OPTION> Option2
............
</SELECT>
Tag SELECT attributes:
1. NAME - a name of a field.
2. MULTIPLE - sets an opportunity of a plural choice.
Tag OPTION attributes:
1. SELECTED - sets the chosen option by default.
Tag TEXTAREA is created on the form with a field of input of the multilower case text. The tag has following syntax:
<TEXTAREA NAME = "name" ROWS=number_strings COLS=number_rows>
The test which will be contained with a field by default
</TEXTAREA>
Tag TEXTAREA has following attributes:
1. NAME - a name of a field.
2. ROWS - height.
3. COLS - width.
Sending of the maintenance of the form occurs by pressing the button "submit". At sending the form on method GET,
script, specified in attribute ACTION of tag FORM contents of the form are transferred in a command line of script
after a symbol "?" In the form of:
name1=value1&name2=value2&.......&nameN=valueN
Where nameX - a name of a field of the form, and valueX - its value. For fields of input of the text or the password
value will be their maintenance entered by the user or established by default, and for chekbox and radio the value
certain in attribute VALUE, will be transferred only for noted buttons. At METHOD = "POST" the line is formed also,
but transferred in a standard stream of input.
|