CGI图文说明教程(6)调用CGI脚本文件的例子之4
发表时间:2024-05-13 来源:明辉站整理相关软件相关文章人气:
[摘要]调用CGI脚本文件的例子//以下是mas_cvo.cpp文件#include "t99_type.h"#include #include inline void html( char str[] ) { cout << str << "\n&q...
调用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; }
// 传递调试选项
// 可以由脚本看到的环境变量
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系统中,最好是使用版本高于2.7.0的gcc编译器,因为这个编译器支持新的数据类型:bool(布尔型)。