I just want to play again with CGI, so today we will make a simple Hello Form.
And Here's the code:
First, the HTML Page:
<form action="/cgi-bin/sayHello" method="post" >
<input type="text" name="username" />
<input type="submit" value="say Hello" />
</form>
And the CGI Script (simple C++ program):
#include <iostream>
#include <cstdlib>
#include <cstring>
using std::cout;
using std::cin;
using std::endl;
int main(void)
{
char* value = new char;
cout<< "Content-type: text/html" << endl << endl;
cin >> value;
char* newValue = new char;
bool toCpy = false;
int cnt = 0;
while (*value != '\0')
{
if (toCpy)
{
*newValue = *value;
newValue++;
cnt++;
}
if (toCpy == false && *value == '=')
{
toCpy = true;
}
value++;
}
newValue = newValue - cnt;
cout<<"Hello " << newValue<<endl;
}
No comments:
Post a Comment