httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ben Kuang <bensdomai...@gmail.com>
Subject [users@httpd] cgi problem
Date Sun, 17 Apr 2005 06:08:51 GMT
Hi: 

I am using apache/cgi/c++ to do a school project on a unix machine.

i wrote a c++ program to get user input from the forms and prints it out.

i compiled the program named it hi.cgi and put its path in the action
field of my html form.
But when I enter the form, instead of running or processing the cgi
program, the browser asks me if i wanna download hi.cgi.  I have
already set the permission string of hi.cgi to (chmod 755).  I am
pulling my hair trying to figure out what is wrong.  Any help would be
appreciated.

Below is my cpp program code:

#include <iostream>
using namespace std;

void EncodeURL(char * buff);

int main(){
	cout << "content-type: text/html\n\n" << endl;
	char * query_string = getenv("QUERY_STRING");
	char name[100];
	int n = 0;
	for(int i=0; query_string[i] != '\0'; i++){
		name[i] = query_string[i];
	}
	
	//cout << "Content-type: text/html/\n\n" << endl;
	cout << "<HTML><HEAD><TITLE>Your name</TITLE></HEAD>\n";
	cout << "<BODY>\n";
		
	EncodeURL(name);
	for(int i=0; name[i] != '\0'; i++){
		cout << name[i];
	}
	
	cout << "</BODY></HTML>" << endl;
}

void EncodeURL(char * buff){
	int x, y;
	char * buff2;
	char * hexstr;
	for(x=0, y=0; x < strlen(buff); x++, y++){
	switch (buff[x]){
	 /* Convert all + chars to space chars */
	 case '+':
	 buff2[y] = ' ';
	 break;

	 /* Convert all %xy hex codes into ASCII chars */
	 case '%':

	 /* Copy the two bytes following the % */
	 strncpy(hexstr, &buff[x + 1], 2);

	 /* Skip over the hex */
	 x = x + 2;

	 /* Convert the hex to ASCII */
         /* Prevent user from altering URL delimiter sequence */
         if( ((strcmp(hexstr,"26")==0)) || ((strcmp(hexstr,"3D")==0)) )
            {
            buff2[y]='%';
            y++;
            strcpy(buff2,hexstr);
            y=y+2;
            break;
            }

	 buff2[y] = (char)strtol(hexstr, NULL, 16);
	 break;

	 /* Make an exact copy of anything else */
	 default:
	 buff2[y] = buff[x];
	 break;
	 }
	}

	strcpy(buff, buff2);
}
		
And the link to the form is here: http://pdc-lab.poly.edu/~rkuang01/index.html
If you type something into the form and press the enter button, the
browser will ask if you wanna save the hi.cgi instead of running it. 
Once again, I have set the permission string to 755.  Thanks in
advance for your help.

Best,

Ben

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Mime
View raw message