CgiCc 使用

一、下载

下载地址:

http://ftp.gnu.org/gnu/cgicc/
ftp://ftp.gnu.org/gnu/cgicc/

二、配置、编译、安装

  • 下载完成后解压:shell tar xzf cgicc-X.X.X.tar.gz
  • 进入解压的目录: ```shell cd cgicc-X.X.X/
  • 配置
./configure --prefix=/opt

--prefix 参数指定安装目录,默认安装目录为/usr

  • 编译
make
  • 安装
make install

三、例程

3.1 如果在64bit平台编译32位库:

CXXFLAGS="-m32" CFLAGS="-m32" LDFLAGS="-m32"

3.2 如果安装目录为/opt:

  • 编译时指定包含路径:shell -I/opt/include
  • 编译时指定引用路径:shell -L/opt/lib

3.3 HTML Demo

testcgi.html

<html>
<head><title>Test CGIcc form</title></head>
<body bgcolor="#cccccc" text="#000000">
<h2>Test CGIcc form</h2>
<p>
<form method="post" action="/cgi-bin/testcgi.cgi">
Value 1 :
<input type="text" name="value1">
<p>
Value 2 :
<select name="value2">
<option value="option1">Option 1
<option value="option2">Option 2
<option value="option3">Option 3
</select>
<P>
Value 3 :
<input type="radio" name="value3" value="button1" checked="checked">Button1
<input type="radio" name="value3" value="button2">Button2 <input type="hidden" name="value4" value="data4">
<p>
<input type="submit" value="Submit">
</form>
</body>
</html>

3.4 C++ CGI Demo

testcgi.cpp

#include <iostream>
#include <vector>
#include <string> #include "cgicc/CgiDefs.h"
#include "cgicc/Cgicc.h"
#include "cgicc/HTTPHTMLHeader.h"
#include "cgicc/HTMLClasses.h" #include <stdio.h>
#include <stdlib.h> using namespace std;
using namespace cgicc; // Or reference as cgicc::Cgicc formData; below in object instantiation. int main(int argc, char **argv)
{
try {
Cgicc formData; // Send HTTP header: Content-type: text/html
cout << HTTPHTMLHeader() << endl; // Print: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
cout << HTMLDoctype(HTMLDoctype::eStrict) << endl; // Print: <html lang="en" dir="LTR">
cout << html().set("lang", "EN").set("dir", "LTR") << endl; // Set up the HTML document
cout << html() << head() << title("Cgicc example") << head() << endl;
cout << body().set("bgcolor","#cccccc").set("text","#000000").set("link","#0000ff").set("vlink","#000080") << endl; cout << h1("This is a demonstration of the GNU CgiCC library") << endl; form_iterator fvalue1 = formData.getElement("value1");
if( !fvalue1->isEmpty() && fvalue1 != (*formData).end()) {
cout << "Value1: " << **fvalue1 << endl;
}
else
cout << "No text entered for value1" << endl; cout << p(); form_iterator fvalue2 = formData.getElement("value2");
if( !fvalue2->isEmpty() && fvalue2 != (*formData).end()) {
// Note this is just a different way to access the string class.
// See the YoLinux GNU string class tutorial.
cout << "Value2: " << (**fvalue2).c_str() << endl;
} cout << p(); form_iterator fvalue3 = formData.getElement("value3");
if( !fvalue3->isEmpty() && fvalue3 != (*formData).end()) {
cout << "Value3: " << **fvalue3 << endl;
} cout << p(); form_iterator fvalue4 = formData.getElement("value4");
if( !fvalue4->isEmpty() && fvalue4 != (*formData).end()) {
cout << "Value4: " << **fvalue4 << endl;
} // Close the HTML document
cout << body() << html();
}
catch(exception& e) {
// handle any errors here.
cout << "ERROR!!" << endl;
}
return 0; // To avoid Apache errors.
}

3.5 编译c++ CGI demo

  • 使用静态库编译

    如果安装在/opt/:g++ -o testcgi.cgi -I/opt/include testcgi.cpp /opt/lib/libcgicc.a

    如果安装在/usr/:g++ -o testcgi.cgi testcgi.cpp /usr/lib/libcgicc.a
  • 使用动态库编译

    如果安装在/opt/:g++ -o testcgi.cgi -I/opt/include testcgi.cpp -L/opt/lib -lcgicc

    如果安装在/usr/:g++ -o testcgi.cgi testcgi.cpp -lcgicc

3.6 运行

  • testcgi.html 拷贝到 /var/www/html/
  • testcgi.cgi 拷贝到 /var/www/cgi-bin/
  • 本机测试 : http://127.0.0.1/testcgi.html

cgicc使用的更多相关文章

  1. 【实习记】2014-08-15文档太少看着源码用cgicc+stl库之模板谓词函数对象

        总结1: 今天找到了昨天scanf的问题答案,scanf与printf一样的神奇而复杂,稍不留神,就会被坑.scanf函数在读入非空白符分割的多个字符串的解决方法是这个:/* 以 | 分割 * ...

  2. 开源C++版本CGI库CGICC入门

    原发布在ChinaUnix,但未自动搬迁过来:http://blog.chinaunix.net/uid-20682147-id-4895772.html PDF版本:https://files-cd ...

  3. Linux环境下使用C/C++编写CGI(httpd)

    step1下载: ftp://ftp.gnu.org/gnu/cgicc/ step2: tar xzf cgicc-X.X.X.tar.gz(用最新版本) cd cgicc-X.X.X ./conf ...

  4. C++常见gcc编译链接错误解决方法

    除非明确说明,本文内容仅针对x86/x86_64的Linux开发环境,有朋友说baidu不到,开个贴记录一下(加粗字体是关键词): 用“-Wl,-Bstatic”指定链接静态库,使用“-Wl,-Bdy ...

  5. C++ CGI Helloword

    一 什么是CGI CGI(The Common Gateway Interface):通用网关接口,定义web服务器和客户脚本进行信息交互的一系列标准.  二 web浏览器 为了了解CGI的概念,让我 ...

  6. FastCGI技术

    1         FastCGI介绍 FastCGI:快速通用网关接口(Fast Common Gateway Interface/FastCGI)是一种让交互程序与Web服务器通信的协议.    ...

  7. 【实习记】2014-08-20实习的mini项目总结

        实习项目总结文档 项目介绍 项目逻辑很简单,只有几个页面,只能登录,查看,支付和退款.主要作用是熟悉C++的cgi的web服务开发方式. 项目页面截图 图一:登录页面 图二:买家查看 图三:买 ...

  8. CGI编程

    1简介 .CGI:通用网关接口(Common Gateway Interface)是一个Web服务器主机提供信息服务的标准接口,服务器和客户端之间的通信,是客户端的浏览器和服务器端的http服务器之间 ...

  9. C++后台实践:古老的CGI与Web开发

    本文写给C/C++程序猿,也适合其他对历史感兴趣的程序猿 ============================================= 谈到web开发,大家首先想到的PHP.JavaEE ...

随机推荐

  1. java高级之Io流

    1.1,什么是io流? 流是一组有顺序的,有起点和终点的字节集合,是对数据传输的总称或抽象.即数据在两设备间的传输称为流,流的本质是数据传输,根据数据传输特性将流抽象为各种类,方便更直观的进行数据操作 ...

  2. Extjs4 修改combox中store的数据

    { xtype: "combo", fieldLabel: '选择模板', name: "TemplateType", fieldName: "Tem ...

  3. C/C++之编程语言学习资源

    前言 因朋友相问,藉以帮助需要学习C.C++语言的后来小伙伴. 网络视频资源 选择其中一系列即可,切忌贪多嚼不烂. [系列1:可能会面临开课时间错过的问题,二门课程只要能上其一即可,均为浙大翁恺老师的 ...

  4. HBase 批量删除表 disable_all drop_all

    这两命令可以匹配正则表达式,对表进行批量操作,也可以对确定名字的单表操作,在表名不存在时,也不会返回exception,只会有提示信息.\ny是为了实现自动确认,因为这两命令需要用户交互确认. 例子, ...

  5. python3.4 + pycharm安装与使用

    因个人是windows的环境,所以本文只讲windows环境下的python安装. 作为初用python的盆友,强烈建议只在电脑上装一个python版本就好了,不然就进了各种坑里了. Python安装 ...

  6. linux如何设置磁盘配额?

    环境:CentOS7 需求:  zhang3 用户在  /dev/sdb1  上,只能使用100M的空间,建立 200个文件. 注意事项:XFS  不能对  /   开启配额             ...

  7. VirtualBox下Centos6.8网络配置

    win10环境下,VirtualBox和Centos6.8已经按照完毕,下面配置Centos6.8网络. 1.设置VirtualBox为桥接模式,具体的有三种联网方法,我们参考http://www.c ...

  8. PTA(Basic Level)1047.编程团体赛

    编程团体赛的规则为:每个参赛队由若干队员组成:所有队员独立比赛:参赛队的成绩为所有队员的成绩和:成绩最高的队获胜. 现给定所有队员的比赛成绩,请你编写程序找出冠军队. 输入格式: 输入第一行给出一个正 ...

  9. MySQL Explain命令详解--表的读取顺序,数据读取操作的类型等

    表示索引中使用的字节数,可通过该列计算查询中使用的索引的长度(key_len显示的值为索引字段的最大可能长度,并非实际使用长度,即key_len是根据表定义计算而得,不是通过表内检索出的) 不损失精确 ...

  10. Linux运维必备工具

    1. 查看进程占用带宽情况 - Nethogs Nethogs 是一个终端下的网络流量监控工具可以直观的显示每个进程占用的带宽. 前提条件:安装c++环境 yum install -y gcc-c++ ...