Name
CGI — CGI support class
Synopsis
CGI provides useful features to implement
Common Gateway Interface (CGI) programs, such as retrieving CGI data
from server, manipulating cookies, and generating the HTTP header and
the HTML body.
Example
require 'cgi'
cgi = CGI::new("html3")
input, = cgi["input"]
if input
input = CGI::unescape(input)
end
p input
begin
value = Thread::new{
$SAFE=4
eval input
}.value.inspect
rescue SecurityError
value = "Sorry, you can't do this"
end
cgi.out {
cgi.html{
cgi.head{cgi.title{"Walter's Web Arithmetic Page"}} +
cgi.body{
cgi.form("post", "/cgi-bin/arith.rb") {
"input your favorite expression: " +
cgi.text_field("input", input) +
cgi.br +
"the result of you input: " +
CGI::escapeHTML(value) +
cgi.br +
cgi.submit
}
}
}
}Required Library
require ‘cgi’
Class Methods
CGI::new([level="query"])Creates a CGI object.
levelmay be one of the following options. If one of the HTML levels is specified, the following methods are defined for generating output conforming to that level:queryNo HTML output generated
html3HTML3.2
html4HTML4.0 Strict
html4TrHTML4.0 Transitional
html4FrHTML4.0 Frameset
CGI::escape(str)Escapes an unsafe string using URL-encoding.
CGI::unescape(str)Expands a string that has been escaped using URL-encoding.
CGI::escapeHTML(str)Escapes HTML special characters, including: & < >.
CGI::unescapeHTML(str)Expands escaped HTML special characters, including: & < >.
CGI::escapeElement(str[,element...])Escapes HTML special characters in the specified HTML elements. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access