这年头用C语言开发cgi的已经不多,大多数的web程序都使用java、php、python等这些语言了。

但是本文将做一些简单的cgi实例。

首先配置环境

#这里是使用的apache

AddHandler 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>

例子

//在目录 /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  

看到如下结果

CGI test


get reuslt:

test=1&asd=1

最新文章

  1. Raft论文的一些问题
  2. 如何在nopcommerce3.3注册页面添加密码强度检查仪?
  3. Java for LeetCode 189 Rotate Array
  4. FTP服务器移动文件目录
  5. Dagger2学习资源
  6. sgu 107 987654321 problem
  7. PID38 串的记数(codevs2077)
  8. (2)入门指南——(3)为什么jquery工作的很好(Why jQuery works well)
  9. StaggeredGridView+universal-image-loader载入网路图片实现瀑布流
  10. html中返回上一页
  11. Effective前端6:避免页面卡顿
  12. etcd 增减节点
  13. LeetCode - Fruit Into Baskets
  14. vue项目,npm install后,npm run dev报错问题
  15. iOS证书(.p12)和描述文件(.mobileprovision)申请
  16. scheduling.quartz.CronTriggerBean has interface org.quartz.CronTrigger as super class
  17. # 20155209 2016-2017-2 《Java程序设计》第六周学习总结
  18. 开发npm模块经验总结
  19. PHP迭代器的小坑
  20. Memcached安装教程及使用

热门文章

  1. 【转】Android API 中文(14) —— ViewStub
  2. bzoj1178
  3. Delphi流的操作 转
  4. 在OCX初始化时获取其在网页中的DOM对象
  5. html checkbox全选或者全不选
  6. 讲解版的自动轮播(新手福利)样式和js就不分离了为了看的方便
  7. 对easyui datagrid进行扩展,当滚动条拉直最下面就异步加载数据。
  8. ZOJ 3430 Detect the Virus 【AC自动机+解码】
  9. 在CentOS 7上利用systemctl加入自己定义系统服务
  10. Java 学习第一天