当前位置:文章写作网 >日记 >日记 >C语言cgi程序在apache上的实现

C语言cgi程序在apache上的实现

2008-12-25 13:55 作者:tshfang 阅读量:203109 推荐21次 | 我要投稿

本文介绍使用apache实现C语言写的cgi程序。

必要条件,安装apache。

首先建立C程序,这里就不多介绍。参照前面的文章或者其它的参考书籍。

建立文件hello.c,内容如下:

#include <stdio.h>

int main()

{

printf("Content-type:text/html\n\n");

printf("<html>");

printf("<head><title>welcome to c cgi.</title></head><body>");

printf("你好:世界<br/>");

printf("</body></html>");

}

编绎hello.c,生成hello.exe。把hello.exe文件拷到 apache安装/cgi-bin/ 目录下。

然后配置 apache 配置文件 httpd.conf。在配制文件中找到

AddHandler cgi-script .cgi 在这一行后面加上 .exe,并且去掉前边的#

最后在浏览器中输入 http://localhost/cgi-bin/hello.exe,回车。

在浏览器中将显示:你好:世界。

通过index.html调用cgi

index.html 文件如下:

<HTML>

<HEAD>

<HEAD>

<BODY>

<FORM ACTION=http://localhost/cgi-bin/cgi.exe METHOD=POST>

<INPUT TYPE=submit VALUE=OK>

</FORM>

</BODY>

</HTML>

在浏览器中输入 http://localhost/index.html,回车。

点击ok按钮,调用cgi程序浏览器显示:你好:世界。

其他人在看啥

    《C语言cgi程序在apache上的实现》的评论 (共 0 条)

    • Guest:Jonny was here
    • Guest:Jonny was here
    • Guest:Punk not dead
    • Guest:i'm fine good work
    • Guest:real beauty page
    • Guest:Thanks funny site
    • Guest:Good crew it's cool :)
    • Guest
    • Guest:Cool site goodluck :)
    • Guest:Very Good Site
    • Guest:Punk not dead
    • Guest:This site is crazy :)
    • Guest:Very Good Site
    • Guest:It's serious
    • Guest:i'm fine good work
    • Guest:i'm fine good work
    • Guest:It's serious
    • Guest:It's serious
    • Guest:comment2
    • Guest:comment5
    • Guest:comment1
    • Guest:comment3
    • Guest:comment2
    • Guest:comment2
    • Guest:comment4
    • Guest:comment6
    • Guest:comment6
    • Guest:comment4
    • Guest:comment5
    • Guest:comment4
    • Guest:comment3
    • Guest:comment3
    • Guest:comment3
    • Guest:comment5
    • Guest:comment2
    • Guest:comment2
    • Guest:comment6
    • Guest:comment4
    • Guest:comment4
    • Guest:comment6
    • Guest:comment2
    • Guest:comment5
    • Guest:comment5
    • Guest:comment5
    • Guest:comment3
    • Guest:comment3
    • Guest:comment6
    • Guest:comment6
    • Guest:comment6
    • Guest:comment4
    • Guest:comment4
    • Guest:comment3
    • Guest:comment6
    • Guest:comment1
    • Guest:comment3
    • Guest:comment6
    • Guest:comment1
    • Guest:comment6
    • Guest:comment3
    • Guest:comment5
    • Guest:comment2
    • Guest:comment2
    • Guest:comment2
    • Guest:comment2
    • Guest:comment4
    • Guest:comment5