📄 cgi.3
字号:
.\" Automatically generated by Pod::Man 2.16 (Pod::Simple 3.05).\".\" Standard preamble:.\" ========================================================================.de Sh \" Subsection heading.br.if t .Sp.ne 5.PP\fB\\$1\fR.PP...de Sp \" Vertical space (when we can't use .PP).if t .sp .5v.if n .sp...de Vb \" Begin verbatim text.ft CW.nf.ne \\$1...de Ve \" End verbatim text.ft R.fi...\" Set up some character translations and predefined strings. \*(-- will.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left.\" double quote, and \*(R" will give a right double quote. \*(C+ will.\" give a nicer C++. Capital omega is used to do unbreakable dashes and.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,.\" nothing in troff, for use with C<>..tr \(*W-.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'.ie n \{\. ds -- \(*W-. ds PI pi. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch. ds L" "". ds R" "". ds C` "". ds C' ""'br\}.el\{\. ds -- \|\(em\|. ds PI \(*p. ds L" ``. ds R" '''br\}.\".\" Escape single quotes in literal strings from groff's Unicode transform..ie \n(.g .ds Aq \(aq.el .ds Aq '.\".\" If the F register is turned on, we'll generate index entries on stderr for.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index.\" entries marked with X<> in POD. Of course, you'll have to process the.\" output yourself in some meaningful fashion..ie \nF \{\. de IX. tm Index:\\$1\t\\n%\t"\\$2"... nr % 0. rr F.\}.el \{\. de IX...\}.\".\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2)..\" Fear. Run. Save yourself. No user-serviceable parts.. \" fudge factors for nroff and troff.if n \{\. ds #H 0. ds #V .8m. ds #F .3m. ds #[ \f1. ds #] \fP.\}.if t \{\. ds #H ((1u-(\\\\n(.fu%2u))*.13m). ds #V .6m. ds #F 0. ds #[ \&. ds #] \&.\}. \" simple accents for nroff and troff.if n \{\. ds ' \&. ds ` \&. ds ^ \&. ds , \&. ds ~ ~. ds /.\}.if t \{\. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u". ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'.\}. \" troff and (daisy-wheel) nroff accents.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'.ds 8 \h'\*(#H'\(*b\h'-\*(#H'.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#].ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#].ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#].ds ae a\h'-(\w'a'u*4/10)'e.ds Ae A\h'-(\w'A'u*4/10)'E. \" corrections for vroff.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'. \" for low resolution devices (crt and lpr).if \n(.H>23 .if \n(.V>19 \\{\. ds : e. ds 8 ss. ds o a. ds d- d\h'-1'\(ga. ds D- D\h'-1'\(hy. ds th \o'bp'. ds Th \o'LP'. ds ae ae. ds Ae AE.\}.rm #[ #] #H #V #F C.\" ========================================================================.\".IX Title "CGI 3".TH CGI 3 "2007-12-18" "perl v5.10.0" "Perl Programmers Reference Guide".\" For nroff, turn off justification. Always turn off hyphenation; it makes.\" way too many mistakes in technical documents..if n .ad l.nh.SH "NAME"CGI \- Simple Common Gateway Interface Class.SH "SYNOPSIS".IX Header "SYNOPSIS".Vb 2\& # CGI script that creates a fill\-out form\& # and echoes back its values.\&\& use CGI qw/:standard/;\& print header,\& start_html(\*(AqA Simple Example\*(Aq),\& h1(\*(AqA Simple Example\*(Aq),\& start_form,\& "What\*(Aqs your name? ",textfield(\*(Aqname\*(Aq),p,\& "What\*(Aqs the combination?", p,\& checkbox_group(\-name=>\*(Aqwords\*(Aq,\& \-values=>[\*(Aqeenie\*(Aq,\*(Aqmeenie\*(Aq,\*(Aqminie\*(Aq,\*(Aqmoe\*(Aq],\& \-defaults=>[\*(Aqeenie\*(Aq,\*(Aqminie\*(Aq]), p,\& "What\*(Aqs your favorite color? ",\& popup_menu(\-name=>\*(Aqcolor\*(Aq,\& \-values=>[\*(Aqred\*(Aq,\*(Aqgreen\*(Aq,\*(Aqblue\*(Aq,\*(Aqchartreuse\*(Aq]),p,\& submit,\& end_form,\& hr;\&\& if (param()) {\& my $name = param(\*(Aqname\*(Aq);\& my $keywords = join \*(Aq, \*(Aq,param(\*(Aqwords\*(Aq);\& my $color = param(\*(Aqcolor\*(Aq);\& print "Your name is",em(escapeHTML($name)),p,\& "The keywords are: ",em(escapeHTML($keywords)),p,\& "Your favorite color is ",em(escapeHTML($color)),\& hr;\& }.Ve.SH "ABSTRACT".IX Header "ABSTRACT"This perl library uses perl5 objects to make it easy to create Webfill-out forms and parse their contents. This package defines \s-1CGI\s0objects, entities that contain the values of the current query stringand other state variables. Using a \s-1CGI\s0 object's methods, you canexamine keywords and parameters passed to your script, and createforms whose initial values are taken from the current query (therebypreserving state information). The module provides shortcut functionsthat produce boilerplate \s-1HTML\s0, reducing typing and coding errors. Italso provides functionality for some of the more advanced features of\&\s-1CGI\s0 scripting, including support for file uploads, cookies, cascadingstyle sheets, server push, and frames..PP\&\s-1CGI\s0.pm also provides a simple function-oriented programming style forthose who don't need its object-oriented features..PPThe current version of \s-1CGI\s0.pm is available at.PP.Vb 2\& http://www.genome.wi.mit.edu/ftp/pub/software/WWW/cgi_docs.html\& ftp://ftp\-genome.wi.mit.edu/pub/software/WWW/.Ve.SH "DESCRIPTION".IX Header "DESCRIPTION".Sh "\s-1PROGRAMMING\s0 \s-1STYLE\s0".IX Subsection "PROGRAMMING STYLE"There are two styles of programming with \s-1CGI\s0.pm, an object-orientedstyle and a function-oriented style. In the object-oriented style youcreate one or more \s-1CGI\s0 objects and then use object methods to createthe various elements of the page. Each \s-1CGI\s0 object starts out with thelist of named parameters that were passed to your \s-1CGI\s0 script by theserver. You can modify the objects, save them to a file or databaseand recreate them. Because each object corresponds to the \*(L"state\*(R" ofthe \s-1CGI\s0 script, and because each object's parameter list isindependent of the others, this allows you to save the state of thescript and restore it later..PPFor example, using the object oriented style, here is how you createa simple \*(L"Hello World\*(R" \s-1HTML\s0 page:.PP.Vb 7\& #!/usr/local/bin/perl \-w\& use CGI; # load CGI routines\& $q = new CGI; # create new CGI object\& print $q\->header, # create the HTTP header\& $q\->start_html(\*(Aqhello world\*(Aq), # start the HTML\& $q\->h1(\*(Aqhello world\*(Aq), # level 1 header\& $q\->end_html; # end the HTML.Ve.PPIn the function-oriented style, there is one default \s-1CGI\s0 object thatyou rarely deal with directly. Instead you just call functions toretrieve \s-1CGI\s0 parameters, create \s-1HTML\s0 tags, manage cookies, and soon. This provides you with a cleaner programming interface, butlimits you to using one \s-1CGI\s0 object at a time. The following exampleprints the same page, but uses the function-oriented interface.The main differences are that we now need to import a set of functionsinto our name space (usually the \*(L"standard\*(R" functions), and we don'tneed to create the \s-1CGI\s0 object..PP.Vb 6\& #!/usr/local/bin/perl\& use CGI qw/:standard/; # load standard CGI routines\& print header, # create the HTTP header\& start_html(\*(Aqhello world\*(Aq), # start the HTML\& h1(\*(Aqhello world\*(Aq), # level 1 header\& end_html; # end the HTML.Ve.PPThe examples in this document mainly use the object-oriented style.See \s-1HOW\s0 \s-1TO\s0 \s-1IMPORT\s0 \s-1FUNCTIONS\s0 for important information onfunction-oriented programming in \s-1CGI\s0.pm.Sh "\s-1CALLING\s0 \s-1CGI\s0.PM \s-1ROUTINES\s0".IX Subsection "CALLING CGI.PM ROUTINES"Most \s-1CGI\s0.pm routines accept several arguments, sometimes as many as 20optional ones! To simplify this interface, all routines use a namedargument calling style that looks like this:.PP.Vb 1\& print $q\->header(\-type=>\*(Aqimage/gif\*(Aq,\-expires=>\*(Aq+3d\*(Aq);.Ve.PPEach argument name is preceded by a dash. Neither case nor ordermatters in the argument list. \-type, \-Type, and \-TYPE are allacceptable. In fact, only the first argument needs to begin with adash. If a dash is present in the first argument, \s-1CGI\s0.pm assumesdashes for the subsequent ones..PPSeveral routines are commonly called with just one argument. In thecase of these routines you can provide the single argument without anargument name. \fIheader()\fR happens to be one of these routines. In thiscase, the single argument is the document type..PP.Vb 1\& print $q\->header(\*(Aqtext/html\*(Aq);.Ve.PPOther such routines are documented below..PPSometimes named arguments expect a scalar, sometimes a reference to anarray, and sometimes a reference to a hash. Often, you can pass anytype of argument and the routine will do whatever is most appropriate.For example, the \fIparam()\fR routine is used to set a \s-1CGI\s0 parameter to asingle or a multi-valued value. The two cases are shown below:.PP.Vb 2\& $q\->param(\-name=>\*(Aqveggie\*(Aq,\-value=>\*(Aqtomato\*(Aq);\& $q\->param(\-name=>\*(Aqveggie\*(Aq,\-value=>[\*(Aqtomato\*(Aq,\*(Aqtomahto\*(Aq,\*(Aqpotato\*(Aq,\*(Aqpotahto\*(Aq]);.Ve.PPA large number of routines in \s-1CGI\s0.pm actually aren't specificallydefined in the module, but are generated automatically as needed.These are the \*(L"\s-1HTML\s0 shortcuts,\*(R" routines that generate \s-1HTML\s0 tags foruse in dynamically-generated pages. \s-1HTML\s0 tags have both attributes(the attribute=\*(L"value\*(R" pairs within the tag itself) and contents (thepart between the opening and closing pairs.) To distinguish betweenattributes and contents, \s-1CGI\s0.pm uses the convention of passing \s-1HTML\s0attributes as a hash reference as the first argument, and thecontents, if any, as any subsequent arguments. It works out likethis:.PP.Vb 6\& Code Generated HTML\& \-\-\-\- \-\-\-\-\-\-\-\-\-\-\-\-\-\-\& h1() <h1>\& h1(\*(Aqsome\*(Aq,\*(Aqcontents\*(Aq); <h1>some contents</h1>\& h1({\-align=>left}); <h1 align="LEFT">\& h1({\-align=>left},\*(Aqcontents\*(Aq); <h1 align="LEFT">contents</h1>.Ve.PP\&\s-1HTML\s0 tags are described in more detail later..PPMany newcomers to \s-1CGI\s0.pm are puzzled by the difference between thecalling conventions for the \s-1HTML\s0 shortcuts, which require curly bracesaround the \s-1HTML\s0 tag attributes, and the calling conventions for otherroutines, which manage to generate attributes without the curlybrackets. Don't be confused. As a convenience the curly braces areoptional in all but the \s-1HTML\s0 shortcuts. If you like, you can usecurly braces when calling any routine that takes named arguments. Forexample:.PP.Vb 1\& print $q\->header( {\-type=>\*(Aqimage/gif\*(Aq,\-expires=>\*(Aq+3d\*(Aq} );.Ve.PPIf you use the \fB\-w\fR switch, you will be warned that some \s-1CGI\s0.pm argumentnames conflict with built-in Perl functions. The most frequent ofthese is the \-values argument, used to create multi-valued menus,radio button clusters and the like. To get around this warning, youhave several choices:.IP "1." 4
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -