这年头用C语言开发cgi的已经不多,大多数的web程序都使用java、php、python等这些语言了。
但是本文将做一些简单的cgi实例。
|
1
2
3
4
5
6
7
8
9
10
11 |
#这里是使用的apacheAddHandler cgi-script .cgi#下面的配置 一般在httpd.conf都已经配好了ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"<Directory "/var/www/cgi-bin"> AllowOverride None Options None Order allow,deny Allow from
all</Directory> |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 |
//在目录 /var/www/cgi-bin 下//添加test.c 文件#include <stdio.h>#include <stdlib.h>#include <string.h>int main(){ char
* out; char
* method; printf("Content-type: text/html\n\n"); printf("<h3>CGI test</h3><hr/>"); method = getenv("REQUEST_METHOD"); //get if(!strcmp(method,"GET")){ out
= getenv("QUERY_STRING"); printf("get reuslt:<br><br>"); printf("%s\n", out); }}//编译的时候把后缀改为.cgi gcc test.c -o test.cgi |
访问 http://localhost/cgi-bin/test.cgi?test=1&asd=1
看到如下结果
get reuslt:
test=1&asd=1
C语言开发CGI程序的简单例子,布布扣,bubuko.com
原文:http://www.cnblogs.com/fengwei/p/3603983.html