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. C#-WinForm跨线程修改UI界面

    待解决的问题 在我做WinForm开发的过程中,经常会遇到耗时操作或阻塞操作.他们会引发软件的卡顿甚至假死,严重影响软件的使用. 因此,这类耗时或阻塞的操作一般都会使用异步的方式去执行,不影响主线程( ...

  2. PHP进阶之路 -- 01 PHP基础语法

    PHP进阶之路 --  PHP基础语法 windows环境下php环境 php定界符  php变量  php数据类型 数据类型转换 检测数据类型 php中三种输出方式 php字符集设置 php常量 p ...

  3. 让nginx 的ssi支持include相对路径

    好久没接触nginx了,今天帮同事解决一个客户的问题,顺便记录下:version : nginx-1.6.2问题描述:客户的files.shtml里面include一个网站的头部文件( <!–# ...

  4. 解决win10 windows mobile 设备中心无法打开问题,MC3200无法连上win10问题

    1.下载高版本的安装包 从微软官方下载:https://www.microsoft.com/zh-cn/download/confirmation.aspx?id=3182 2.  运行service ...

  5. flask 之(四) --- 扩展|缓存|会话

    扩展 蓝图内置扩展 (实现的是路由的拆分) '''----------- app.py -------------''' from flask import Flask from users_view ...

  6. python高级 之(四) --- 模块方法

    模块 时间模块:time/datatime/calendar. 系统操作文件模块:os time模块 介绍 import time # 获取当前时间, 结果是存在时间元组中的.星期一是从0开始的 # ...

  7. 致远OA利用POC

    批量检测url 在脚本同目录下建立url.txt 放入待检测的URL 运行脚本 # Wednesday, 26 June 2019 # Author:nianhua # Blog:https://gi ...

  8. 学python的第三天

    函数的作用 不知道大家是否注意到,在上面的代码中,我们做了3次求阶乘,这样的代码实际上就是重复代码.编程大师Martin Fowler先生曾经说过:“代码有很多种坏味道,重复是最坏的一种!”,要写出高 ...

  9. VisualBasic文件与目录管理FileSystem 类

    注解 下表列出了涉及 My.Computer.FileSystem 对象的任务示例. 功能 查看 从文本文件读取 如何:读取文本文件 从带分隔符的文本文件中读取 如何:读取逗号分隔的文本文件 从固定宽 ...

  10. Oracle块,区,段

    数据块(Block) 数据块Block是Oracle存储数据信息的最小单位.注意,这里说的是Oracle环境下的最小单位.Oracle也就是通过数据块来屏蔽不同操作系统存储结构的差异.无论是Windo ...