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. Powershell重命名文件夹

    $TargetFolder = "F:\Code\优化后\" $folders = get-childitem $TargetFolder -forceForeach ($Fold ...

  2. 【HANA系列】SAP HANA SQL获取时间中的小时

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP HANA SQL获取时间 ...

  3. 【POJ - 3187】Backward Digit Sums(搜索)

    -->Backward Digit Sums 直接写中文了 Descriptions: FJ 和 他的奶牛们在玩一个心理游戏.他们以某种方式写下1至N的数字(1<=N<=10). 然 ...

  4. IP划分

      30.112.0.0 255.255.224.0/ 30.112.32.0 255.255.248.0 30.112.36.0 255.255.252.0 30.112.38.0 255.255. ...

  5. Eclipse新建新的工作空间,将原有的配置全部或部分复制

    1.部分复制 File->Switch workspace->Other...,按下图选择 只复制简单的配置,如cvs之类的信息是不会复制的. 2.全部复制(build path) 在1. ...

  6. 【linux开发】IO端口和IO内存的区别及分别使用的函数接口

    IO端口和IO内存的区别及分别使用的函数接口 每个外设都是通过读写其寄存器来控制的.外设寄存器也称为I/O端口,通常包括:控制寄存器.状态寄存器和数据寄存器三大类.根据访问外设寄存器的不同方式,可以把 ...

  7. Linux 中账户管理

    账户管理涉及到三个文件: 1./etc/passwd yy@ubuntu:~$ head -n 3 /etc/passwdroot:x:0:0:root:/root:/bin/bashdaemon:x ...

  8. mysql——修改表名、修改字段名、修改字段数据类型、增加字段、删除字段、修改字段排列位置、修改存储引擎、删除表 (示例)

    一.创建表和插入数据: ), mz ), bz ) ); ,'sww','sww01'); ,'aww','aww02'); ,'qww','qww03'), (,'eww','eww04'), (, ...

  9. div随着屏幕滚动而滚动

    <script type="text/javascript"> $(document).ready(function () { var menuYloc = $(&qu ...

  10. 使用PowerShell 将用户添加至用户组

    执行环境:Windows Server 2012 R2 语法 net localgroup 用户组名称 用户名 /add eg. net localgroup administrators myboo ...