明輝手游網(wǎng)中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

CGI圖文說明教程(6)調(diào)用CGI腳本文件的例子之4

[摘要]調(diào)用CGI腳本文件的例子//以下是mas_cvo.cpp文件#include "t99_type.h"#include #include inline void html( char str[] ) { cout << str << "\n&q...
調(diào)用CGI腳本文件的例子

//以下是mas_cvo.cpp文件

#include "t99_type.h"

#include

#include

inline void html( char str[] ) { cout << str << "\n"; }

inline void html_( char str[] ) { cout << str; }

inline void html_( char c ) { cout << c; }

// 傳遞調(diào)試選項

// 可以由腳本看到的環(huán)境變量

char* getenv_n( char var[] )

{

char *p = getenv( var );

return p == NULL ? (char*)"[]" : p;

}

void cgi_var_output( )

{

html("");

html("");

html( "
" );

html_("AUTH_TYPE "); html( getenv_n( "AUTH_TYPE" ) );

html_("CONTENT_LENGTH "); html( getenv_n( "CONTENT_LENGTH" ) );

html_("CONTENT_TYPE "); html( getenv_n( "CONTENT_TYPE" ) );

html_("GATEWAY_INTERFACE "); html( getenv_n( "GATEWAY_INTERFACE" ) );

html_("HOSTTYPE "); html( getenv_n( "HOSTTYPE" ) );

html_("HTTP_ACCEPT "); html( getenv_n( "HTTP_ACCEPT" ) );

html_("HTTP_CONNECTION "); html( getenv_n( "HTTP_CONNECTION" ) );

html_("HTTP_HOST "); html( getenv_n( "HTTP_HOST" ) );

html_("HTTP_PRAGMA "); html( getenv_n( "HTTP_PRAGMA" ) );

html_("HTTP_REFERER "); html( getenv_n( "HTTP_REFERER" ) );

html_("HTTP_USER_AGENT "); html( getenv_n( "HTTP_USER_AGENT" ) );

html_("OSTYPE "); html( getenv_n( "OSTYPE" ) );

html_("PATH_INFO "); html( getenv_n( "PATH_INFO" ) );

html_("PATH_TRANSLATED "); html( getenv_n( "PATH_TRANSLATED" ) );

html_("QUERY_STRING "); html( getenv_n( "QUERY_STRING" ) );

html_("REMOTE_ADDR "); html( getenv_n( "REMOTE_ADDR" ) );

html_("REMOTE_HOST "); html( getenv_n( "REMOTE_HOST" ) );

html_("REMOTE_IDENT "); html( getenv_n( "REMOTE_IDENT" ) );

html_("REMOTE_USER "); html( getenv_n( "REMOTE_USER" ) );

html_("REQUEST_METHOD "); html( getenv_n( "REQUEST_METHOD" ) );

html_("SCRIPT_NAME "); html( getenv_n( "SCRIPT_NAME" ) );

html_("SERVER_NAME "); html( getenv_n( "SERVER_NAME" ) );

html_("SERVER_PORT "); html( getenv_n( "SERVER_PORT" ) );

html_("SERVER_PROTOCOL "); html( getenv_n( "SERVER_PROTOCOL" ) );

html_("SERVER_SOFTWARE "); html( getenv_n( "SERVER_SOFTWARE" ) );

html("<P>");

html("Unix command printenv");

cout << flush;

system( "printenv sort" );

html("

");

html("Unix command set");

cout << flush;

system( "set sort " );

html( "

" );

html( "" );

html( "" );

}

  實際上,CGI腳本也可以用其它的語言來編寫。如果你使用C語言來編寫并且是在UNIX系統(tǒng)中,最好是使用版本高于2.7.0的gcc編譯器,因為這個編譯器支持新的數(shù)據(jù)類型:bool(布爾型)。