+ -
当前位置:首页 → 问答吧 → C写的处理method=get表单的cgi程序

C写的处理method=get表单的cgi程序

时间:2007-01-04

来源:互联网

index.html的大致内容:

11     <table border="0">
12     <tr><td width="350"></td><td width="350"></td><td
width="350"></td></tr>
13     <!--      序章-死灵法师   -->
14     <tr><td colspan="3"
align="center">序章-死灵法师</td></tr>
15     <tr>
16     <td width="33%" align="center">
17         <button type="submit" name="filename"
value="000_001">序章上 前夜</button>

main.c

  1 #include <stdio.h>
  2 #include <stdlib.h>
  3 #include <errno.h>
  4
  5 #define BUF_N   512
  6 #define PATH    "../xiedu/"
  7
  8 static inline void
  9 begin(void)
10 {
11     fprintf(stdout,"Content-type:text/html\n\n");
12     fprintf(stdout,"<html><title>亵渎</title>\n");
13     return;
14 }
15 static inline void
16 end(void)
17 {
18     fprintf(stdout,"</html>");
19     return;
20 }
21 static void
22 content(const char * const path)
23 {
24     FILE * fp = fopen(path,"rb");
25     char * buf = NULL;
26     if( NULL == fp ){
27         fprintf(stdout,"%d:打开错误</br>\n",__LINE__);
39     free(buf);
40     fclose(fp);
41     return;
42 }
43 int
44 main(int argc,char **argv)
45 {
46     int i,n=0;
47     begin();
48     /*    method = get */
49     if( getenv("QUERY_STRING" ) ){
50         char *t=NULL;
51         if( NULL == (t=(char *)malloc(sizeof(char)*BUF_N)) ){
52             end();
53             exit(-1);
54         }
55         sprintf(t,"%s",PATH);
56         strcat(t,strstr((char *)getenv("QUERY_STRING"),"=")+1);
57         /*
58         fprintf(stdout,"打开文件:%s</br>\n",t);
59         */
60         content(t);
61         free(t);
62     }
63     end();
64     return 0;
65 }

作者: 洗脚   发布时间: 2007-01-04

这个比较奇

作者: leehui1983   发布时间: 2007-01-04

好原始的处理方法,:L

作者: cator   发布时间: 2007-01-04

:$ php还没用顺手

作者: 洗脚   发布时间: 2007-01-04