int cgiMain() {
#if DEBUG
/* Load a saved CGI scenario if we're debugging */
cgiReadEnvironment("/path/to/capcgi.dat");
#endif
/* Important: we must indicate the type of document */
cgiHeaderContentType("text/html");
/* Now invoke other functions to handle each part of the form */
fprintf(cgiOut, "\n");
fprintf(cgiOut, "cgic test\n"):
fprintf(cgiOut, "
cgic test
\n");
Name();
Address();
Hungry();
Temperature();
Frogs();
Color();
Flavors();
NonExButtons();
RadioButtons();
fprintf(cgiOut, "
\n");
/* This value will be the exit code of the program; 0
generally indicates success among Unix and DOS programs */
return 0;
}
int cgiMain() {
int colorChosen;
gdImagePtr im;
int r, g, b;
/* Use gdto create an image */
im = gdImageCreate(64, 64);
r = gdImageColorAllocate(im, 255, 0, 0);
g = gdImageColorAllocate(im, 0, 255, 0);
b = gdImageColorAllocate(im, 0, 0, 255);
/* Now use cgic to find out what color the user requested */
cgiFormSelectSingle("color", 3, &colorChosen, 0);
/* Now fill with the desired color */
switch(colorChosen) {
case 0:
gdImageFill(im, 32, 32, r);
break;
case 1:
gdImageFill(im, 32, 32, g);
break;
case 2:
gdImageFill(im, 32, 32, b);
break;
}
/* Now output the image. Note the content type! */
cgiHeaderContentType("image/gif");
/* Send the image to cgiOut */
gdImageGif(im, cgiOut);
/* Free the gd image */
gdImageDestroy(im);
return 0;
}
4.CGI调试特征: 利用捕获
为调试而捕捉CGI状态
5.cgic函数参考
cgiFormResultType cgiFormString( char *name, char *result, int max)
用于从输入域中copy字符串。他将域名max-1字节中的字符copy到缓冲区result。若域不存在,则copy一个空串到result缓冲区。在此函数中所有的新行由换行符代表。
cgiFormResultType cgiFormStringNoNewlines( char *name, char *result, int max)
它与cgiFormString函数相似,只是所有的CR和LF都被去掉了。
cgiFormResultType cgiFormStringSpaceNeeded( char *name, int *length)
它返回指向name的字符串的长度,并将长度放入length中。
cgiFormResultType cgiFormSelectSingle( char *name, char **choicesText, int choicesTotal, int *result, int defaultV)
取出复选框(跟在select语句之后的),把选择的名字copy到choicesText,把选择的个数copy到choicesTotal,把当前的选择copy到result。
cgiFormResultType cgiFormSelectMultiple( char *name, char **choicesText, int choicesTotal, int *result, int *invalid)
与cgiFormSelectSingle类似,只指向整型数组的result代表了选择的项。
This section provides a reference guide to the various global variables provided by cgic for the program mer to utilize. These variables should always be used in preference to
stdin, stdout, and calls to getenv() in order to ensure compatibility
with the cgic CGI debugging features.
大多数的变量相当于各种CGI变量,重要的是VGIC的变量不能为空.