C++はCGIのWEBプログラミングを行う
一、CGIとは
パブリックゲートウェイインタフェース(CGI)は、Webサーバとクライアントスクリプトの間で情報がどのように交換されるかを定義する標準です.
CGI仕様は現在NCSAによって維持されており、NCSAはCGIを以下のように定義している.
共通ゲートウェイインタフェース(CGI)は、外部ゲートウェイプログラムがHTTPサーバなどの情報サーバとドッキングするためのインタフェース標準である.
現在のバージョンはCGI/1.1で、CGI/1.2バージョンは進行中です.
共通ゲートウェイインタフェース(CGI)は、アプリケーション(CGIプログラムまたはCGIスクリプトと呼ばれる)がWebサーバおよびクライアントと対話できるようにする標準プロトコルである.
これらのCGIプログラムはPython,PERL,Shell,CまたはC++などで記述できる.
二、CGIプログラム開発
1、apacheのインストール
2、cgiccライブラリのインストール
注意:libcgicc.soとlibcgicc.aライブラリは/usr/libディレクトリにインストールされ、コピーコマンドを実行する必要があります:sudo cp/usr/lib/libcgicc.*/USr/lib 64/は、CGIプログラムが自動的にlibcgiccを見つけることができる.soダイナミックリンクライブラリ.
3、テストプログラムの作成
4、コンパイラ
5.mainを生成する.cgi、CGIディレクトリに入れます
次のリンクを使用してアクセスを試みます.
http://localhost/cgi-bin/main.cgi?first_name=ZARA&last_name=ALI
ブラウザから以下の結果が出力されます:名前:ZARA姓:ALI
パブリックゲートウェイインタフェース(CGI)は、Webサーバとクライアントスクリプトの間で情報がどのように交換されるかを定義する標準です.
CGI仕様は現在NCSAによって維持されており、NCSAはCGIを以下のように定義している.
共通ゲートウェイインタフェース(CGI)は、外部ゲートウェイプログラムがHTTPサーバなどの情報サーバとドッキングするためのインタフェース標準である.
現在のバージョンはCGI/1.1で、CGI/1.2バージョンは進行中です.
共通ゲートウェイインタフェース(CGI)は、アプリケーション(CGIプログラムまたはCGIスクリプトと呼ばれる)がWebサーバおよびクライアントと対話できるようにする標準プロトコルである.
これらのCGIプログラムはPython,PERL,Shell,CまたはC++などで記述できる.
二、CGIプログラム開発
1、apacheのインストール
sudo yum install httpd httpd-dev
2、cgiccライブラリのインストール
wget http://ftp.gnu.org/gnu/cgicc/cgicc-3.2.16.tar.gz
tar zxvf cgicc-3.2.16.tar.gz
cd cgicc-3.2.16
./configuer
make
sudo make install
注意:libcgicc.soとlibcgicc.aライブラリは/usr/libディレクトリにインストールされ、コピーコマンドを実行する必要があります:sudo cp/usr/lib/libcgicc.*/USr/lib 64/は、CGIプログラムが自動的にlibcgiccを見つけることができる.soダイナミックリンクライブラリ.
3、テストプログラムの作成
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
using namespace cgicc;
int main ()
{
Cgicc formData;
cout << "Content-type:text/html\r
\r
";
cout << "
";
cout << "
";
cout << " GET POST
";
cout << "
";
cout << "
";
form_iterator fi = formData.getElement("first_name");
if(!fi->isEmpty() && fi != (*formData).end()) {
cout << " :" << **fi << endl;
}else{
cout << "No text entered for first name" << endl;
}
cout << "
";
fi = formData.getElement("last_name");
if(!fi->isEmpty() &&fi != (*formData).end()) {
cout << " :" << **fi << endl;
}else{
cout << "No text entered for last name" << endl;
}
cout << "
";
cout << "
";
cout << "
";
return 0;
}
4、コンパイラ
g++ -I/usr/include -L/usr/lib -lcgicc -o main.cgi main.cpp
sudo cp ./main.cgi /var/www/cgi-bin/
5.mainを生成する.cgi、CGIディレクトリに入れます
次のリンクを使用してアクセスを試みます.
http://localhost/cgi-bin/main.cgi?first_name=ZARA&last_name=ALI
ブラウザから以下の結果が出力されます:名前:ZARA姓:ALI