vi posto un codice che crea un eseguibile cgi.
Dovete compilarlo e compiarlo nella cartella cgi-bin del vostro server, ed eseguirlo da un browser con http://vostro_server/cgi-bin/nome_eseguibile, questo è tutto.
codice:
#include <iostream>
using namespace std;
/* urldecode - v. RFC 1738 per i dettagli */
string urldecode (string &input)
{
string str ;
char c, c1, c2;
const char *in = input.c_str();
while (c = *in) {
if( c == '%' ) {
c1 = *(++in);
c2 = *(++in);
// if( c1 == EOF || c2 == EOF ) exit(0);
c1 = tolower(c1);
c2 = tolower(c2);
if( ! isxdigit(c1) || ! isxdigit(c2) ) return str;
if( c1 <= '9' )
c1 = c1 - '0';
else
c1 = c1 - 'a' + 10;
if( c2 <= '9' )
c2 = c2 - '0';
else
c2 = c2 - 'a' + 10;
str += 16 * c1 + c2 ;
}
else if( c == '+' )
str += ' ' ;
else
str += c ;
in++;
}
return str;
}
int main (int argc, char *argv[])
{
string document_root ;
string method ;
unsigned int length ;
if ( getenv( "DOCUMENT_ROOT" ) )
document_root = getenv( "DOCUMENT_ROOT" );
if ( getenv( "REQUEST_METHOD") )
method = getenv( "REQUEST_METHOD" );
if ( getenv( "CONTENT_LENGTH" ) )
length = atoi( getenv( "CONTENT_LENGTH" ) );
else length = 0;
string the_query_string = "";
if ( method == "POST" ) {
if ( length > 0 ) {
char * str = new char [length];
cin.read (str, length);
the_query_string = str;
delete [] str;
}
}
else if ( method == "GET" ) {
if ( getenv("QUERY_STRING") )
the_query_string = getenv("QUERY_STRING");
the_query_string = urldecode(the_query_string);
}
else {
string s1;
while ( cin >> s1 )
the_query_string += s1;
}
cout << "Content-type: text/html" << endl << endl;
cout << "query-string = " << the_query_string << endl;
return (0);
}
il codice è autoesplicativo, se c'è qualcosa di non chiaro chiedete pure
ciao
sergio