I am having an error that I can't seem to get past. The problem I get is an internal server error 500 when I try to run the C++ CGI script. here is my HTML document. I am using Apache Web Server.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head><title>Welcome To My NumberGuessing Game!</title></head>
<body>
<h1> Welcome To My Number Guessing Game!!</h1><br>
<form method="get" action="http://localhost/cgi-bin/getNum.exe">
Guess a number in between 1 and 100: <input name="guess"><br>
<input type="submit" value="Try My Luck">
</body>
</html>
Here is my server program please just assume parse.cpp and parse.h are working properly because they were given. Here is my C++ server. Any help is always appreciated.
Code blocks are created by indenting at least 4 spaces
... and can span multiple lines
using namespace std;
void main()
{
char* varptr;
char* sptr;
int guesses = 0;
int visits = 0;
int random = 0;
string result;
size_t size;
srand(time(0));
_dupenv_s(&varptr, &size, "HTTP_COOKIE");
if(varptr != 0)
{
Parse list( varptr );
sptr = list.get_item( "VISITS" );
if (sptr != NULL)
{
sscanf_s(sptr, "%d", &visits);
delete [] sptr;
}
sptr = list.get_item( "RANDOM_NUMBER" );
if (sptr != NULL)
{
sscanf_s(sptr, "%d", &random);
delete [] sptr;
}
visits++;
free(varptr);
}
if (random = 0)
{
random = 1 + (rand() % 100);
}
cout << "Set-Cookie: VISITS=" << visits << endl;
cout << "Set-Cookie: RANDOM_NUMBER=" << random << endl;
_dupenv_s(&varptr, &size, "QUERY_STRING");
if(varptr != 0)
{
Parse list( varptr );
sptr = list.get_item( "guess" );
if (sptr != NULL)
{
sscanf_s(sptr, "%d", &guesses);
if (guesses < random)
{
result = "Too Low Please Try Again";
}
else if (guesses > random)
{
result = "Too High Please Try Again";
}
else if (guesses == random)
{
result = "Excellent!! You Guessed right Please Play Again!!";
visits = 0;
cout << "Set-Cookie: VISITS=" << visits << endl;
random = 1 + (rand() % 100);
cout << "Set-Cookie: RANDOM_NUMBER=" << random << endl;
}
delete [] sptr;
}
free(varptr);
}
cout << "<!DOCTYPE HTML PUBLIC " << "\"" << "-//W3C//DTD HTML 4.0 Transitional//EN"
<< "\"" << "\"" << " http://www.w3.org/TR/REC-html40/loose.dtd" << "\"" << ">";
cout << "<html>";
cout << "<head><title>Welcome To My NumberGuessing Game!</title></head>";
cout << "<body>";
cout << "<h1> Welcome To My Number Guessing Game!!</h1><br>";
cout << result << "<br>";
cout << "The number of guesses = " << visits << "<br>";
cout << "<form method="<< "\"" << "get" << "\"" << " action="<< "\""
<<"http://localhost/cgi-bin/getNum.exe"<< "\"" << ">";
cout << "Guess a number in between 1 and 100: <input name="<< "\"" << "guess"<< "\"" << "><br>";
cout << "<input type="<< "\"" << "submit"<< "\"" << " value=" << "\"" << "Try My Luck"<< "\"" << ">";
cout << "</body>";
cout << "</html>";
}