什么是CGI文件

 CGI(Common Gateway Interface)是HTTP服务器运行的程序

CGI处理步骤:

通过Internet把用户请求送到服务器

服务器接收用户请求并交给CGI程序处理

CGI程序把处理结果传送给服务器

服务器把结果送回到用户。

 <a href="/cgi-bin/general/general.cgi" class="link_area" id="Setting">
             <script type="text/javascript">document.write(mLink_Setting);</script>
  </a>

如下图点击setting按钮,然后服务器就会执行general.cgi并把结果返回给客户。

 

如何编写cgi文件

例如用CGIC库编写文件上传的服务端程序

编写upload.c后

gcc -Wall upload.c cgic.c -o upload.cgi
 
编写相应的upload.html
< form target = " _blank " method = " post " action = " cgi-bin/upload.cgi " >

<input name="file" type="file" /> <input name="submit" type="submit" />

</form>

最后的文件目录结构为
/MyWebRoot
|—/upload.html
|—/cgi-bin
|——/upload.cgi

 

或者shell写cgi

我的文件是test.cgi,存放在/usr/local/apache2/cgi-bin/下面,内容如下:

#!/bin/bash

echo Content-type: text/html; charset=gb2312

echo

echo "<HTML><PRE>"

echo "<head>"

echo "<title>sophia test file</title>"

echo "<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />"

echo "</head>"

echo "hello"

echo "</PRE></HTML>"


https://localhost/cgi-bin/test.cgi 访问

 

  • 7
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值