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

来源:互联网 发布:心理学理论书籍 知乎 编辑:程序博客网 时间:2024/05/29 09:53

本文介绍使用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,回车。
在浏览器中将显示:你好:世界。
0 0
原创粉丝点击