k24:k24.6:k24.6.1:start
Table of Contents
24.6.1 Class CGI
The CGI (gb.web) class contains methods for accessing environment variables that you can use in your CGI projects.
24.6.1.1 Methods
The CGI class has only these four methods:
| Method | ReturnType | Description |
|---|---|---|
| Encode ( Path As String ) | String | Encodes a URL into the Application/x-www-form-urlencoded format. |
| Decode ( Path As String ) | String | Decodes a URL from the Application/x-www-form-urlencoded-Format. |
| FormatDate ( dDate As Date ) | String | Formats a date into the RFC-822 date format. The function value is of data type 'String'. |
| Error ( Text As String ) | String | The method tries to insert an error message into the HTML output. The result of this method depends on what has already been sent to the client. |
Table 24.6.1.1 : Methods of the CGI class.
Notes:
- It is interesting to note the information in RFC 1738, which sets out the specifications on how to correctly notate a URL (Uniform Resource Locator) for different Internet services. These specifications are implemented in the two methods Encode(..) and Decode(..).
- In the RFC 822, you can find the syntax for the RFC 822 date format at http://www.faqs.org/rfcs/rfc822.html in section '5 DATE AND TIME SPECIFICATION'.
24.6.1.2 Examples
Print CGI.Encode("http://www.gambas-buch.de/dw/doku.php?id=k18:start")
Print CGI.Decode("http%3A%2F%2Fwww.gambas-buch.de%2Fdw%2Fdoku.php%3Fid%3Dk18%3Astart")
Print CGI.FormatDate(Now)
Print CGI.Error("Das ging schief...!")
Outputs in the console of the Gambas IDE:
http%3A%2F%2Fwww.gambas-buch.de%2Fdw%2Fdoku.php%3Fid%3Dk18%3Astart http://www.gambas-buch.de/dw/doku.php?id=k18:start Sat, 19 Jul 2014 18:36:13 GMT <h1>Error in CGI script</h1><pre>Das ging schief...!</pre>
24.6.1.3 Reading and setting environment variables
However, you can also use the CGI class like an array to read ( CGI[..] ) or set ( CGI[..] = … ) the value of environment variables - as shown in the following examples:
- Application.Host is an equivalent for CGI[“HTTP_HOST”].
- Request.Query is an equivalent for CGI[“QUERY_STRING”].
- Request.Path is an equivalent for CGI[“PATH_INFO”].
- IF Upper(CGI[“REQUEST_METHOD”]) = “GET” THEN …
For an overview of CGI environment variables, see the link:
http://de.selfhtml.org/servercgi/cgi/umgebungsvariablen.htm
k24/k24.6/k24.6.1/start.txt · Last modified: by 127.0.0.1
