We were asked to create a log-in page in HTML/CGI. I came up with this code:
#include
#include
#include
char username[20];
char password[20];
char* extract_value(char* data,int data_len, char* name, char* dest);
int main()
{
int size;
char *buff;
printf("Content-type:text/html\n\n");
printf("
");buff = getenv("CONTENT_LENGTH");
if (buff)
size = atoi(buff);
char data[size+1];
int i;
for(i=0;i
data[i]=fgetc(stdin);
data[size]='\0';
extract_value(data,size+1,"username",username);
extract_value(data,size+1,"password",password);
printf("");
}
char* extract_value(char* data,int data_len, char* name, char* dest)
{
int i,j,k,flag,carry;
for(i=0;i
flag=1;
for(j=0,k=0;name[j]!='\0';j++,k++)
{
if(j>=data_len)
{
i=data_len;
break;
}
else if(name[j]!=data[i+k]){
flag=0;
break;
}
carry=i+k+2;
}
if(flag)
{
j=carry;
for(k=0;data[j]!='&'&&data[j]!='\0';j++,k++)
{
dest[k]=data[j];
}
dest[k]='\0';
break;
}
}
return dest;
}
And here's my HTML program:
Username:
Password:
After compiling it and running it through Apache/XAMPP, it comes up with this error:
Server error!
The server encountered an internal error and was unable to complete your request.
Error message:
End of script output before headers: 11.cgi
If you think this is a server error, please contact the webmaster.
Any idea how to fix this type of problem? Thanks a lot!