CGI - Sending data to a CGI script

December 2016




The sending of data to a CGI script is done via an HTML form.

HTML forms are created using the <FORM> tag, containing buttons, fields, lists and check boxes, labeled with names that will involve values, user input functions and a submit button on the form that will send all the information collected to the specified script as the Action attribute of the FORM tag (via the GET or POST method). Each element of the form must have a unique name, which combined to its value will create a pair of this type:
Name_of_element=value

The name/value sets are separated by ampersands ("&" ). Thus, when sending a form creates a string of the form:
field1=value1&field2=value2&field3=value3

This string will be different depending on whether the method used to submit the form is GET or POST.

GET and POST methods


The GET method sends the form elements through the URL of the script. It will add the name\value pairs to the URL of the script, separating each element using a question mark, thus giving a URL like this:

http://name_of_server/cgi-bin/script.cgi?field1=value1&field2=value2...

However, the length of the URL string is limited to 255 characters, information beyond this limit will be permanently lost. In addition, it creates a overloaded URL in the address bar of a browser and can reveal sensitive information like a password ...etc

Thus, the POST method is a good alternative to the GET method. This method encodes the information in the same way as the GET method (URL encoding and name/value pairs), but it sends the data in a field called the "body of the request". In this way the amount of data sent is not limited!

Related :

This document entitled « CGI - Sending data to a CGI script » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.