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. for...in 与 for...of

    在js中, 对于Object,一般for...in 来进行迭代,不能使用for...of     // let obj = {a:1,b:2} for(let i of obj){console.lo ...

  2. 让mysql返回的结果按照传入的id的顺序排序

    比如id为 1,3,5,44,66,32,21,6 那么返回的结果顺序也是这个顺序   $sql = "select * from ".$this->tableName(). ...

  3. Jenkins 有用的API

    /quietDown: Put Jenkins in a Quiet mode, in preparation for a restart. In that mode Jenkins don’t st ...

  4. fio 硬盘测试工具

    一.windows环境 1. 安装fio:http://www.bluestop.org/fio/ 可以选择不同版本的安装,安装后在C:\Program Files\fio目录中可以找到fio的执行程 ...

  5. 使用Python过程中遇到的一些坑及其解决方法(持续更新)

    1.列表不能直接赋值 nums1 = nums2 x nums1[:] = nums2 正确 2.返回列表某一元素的值可以使用index函数 aList = [123, 'xyz', 'runoob' ...

  6. flask_alembic操作

    HOSTNAME = '127.0.0.1' PORT = 3306 DATABASE = 'first_sqlalchemy_demo' USERNAME = 'root' PASSWORD = ' ...

  7. linux分区知识

    1.硬盘使用前,一般要分区,格式化(创建文件系统)--存放数据(极端情况下,可以不分区) 2.分区: 主分区. 扩展分区.逻辑分区 主分区+拓展分区的数量<=4,其中一个主分区可以用一个拓展分区 ...

  8. Macaca环境搭建(二)----uirecorder PC录制

    上一节我们安装好了macaca环境,这节我们来进行PC录制: 一.安装UI Recorder 命令窗口输入:npm install uirecorder mocha -g 二.初始化配置 1.创建文件 ...

  9. 第四周课程总结&实验报告二

    第四周课程总结 第四周课程总结 本周重点为学习String;首先String用以创建字符串,且通过有一次课堂练习加强理解到:String 类是不可改变的,一旦创建了 String 对象,那它的值就无法 ...

  10. Java小知识----POI事件模式读取Excel 2007

    一.知识背景 1.读取excel的方法选择问题 java中读excel中的时间,我们通常用POI去解析,在使用new HSSFWorkbook(NEW FileInputStream(excelFil ...