|
-
March 18th, 2002, 06:48 AM
#1
C/C++ CGI Executables
Hello,
I'm have a fair amount of experience in C/C++, but am just venturing into CGI, and am having no luck getting the simplest CGI executable to work. The server I am uploading to is a UNIX, and I am compiling my C files with Visual Studio 5.0. When I run the executable on the command prompt, I get the desired output, but when I put it in the cgi-bin directory on the server, and attempt to run it, it gives me the download dialog. And then if I try to execute it using server side includes it says "an error occurred while processing directive". I have tried naming the file with both the .exe and .cgi extension. Any tips would be greatly appreciated!
Thanks in advance!
-
March 18th, 2002, 05:11 PM
#2
Re: C/C++ CGI Executables
There is a setting for the directory on the server that decides whether to execute and executable file or download it. Sounds like that setting or the read/write permissions for the directory and/or the file on the server are incorrect.
(Most servers require executable files to have a permissions setting of 755. I think the directory must ahve the same setting.)
-
May 6th, 2002, 05:42 AM
#3
Re: C/C++ CGI Executables
Hi , firstly You need to compile Your c/c++ code for the UNIX platform using gcc or g++ compiler.Then to setup executable permissions.I think it will help you
Just an short example.
/* CGI Message */
/*
<form>
<input type=text name="name">
<input type=text name="login">
<input type=text name="mes" width=100 height=50>
</form>
*/
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TEST_MODE 0
#if TEST_MODE
#include <conio.h>
#endif
int main(void)
{
char *QUERY_STRING;
FILE *message;
char *ptr;
char Name[50],LogIn[50],Message[4096];
/* char *qstr;
qstr=QUERY_STRING;*/
printf( "Content-type: text/html\n\n" );
fflush( stdout );
QUERY_STRING = NULL;
#if TEST_MODE
QUERY_STRING = "name:Alex&login:alst1204&message:Something for you";
#else
QUERY_STRING = getenv( "QUERY_STRING" );
#endif
/* printf( "QUERY_STRING : " );
fflush( stdout );
printf( QUERY_STRING );
fflush( stdout );*/
ptr=strstr(QUERY_STRING,"name");
ptr+=5;
char *tmp;
/* Getting 'name' from QUERY_STRING */
tmp=Name;
do{
*tmp=*ptr;
tmp++;
ptr++;
}while(*ptr!=38);
*tmp=0;
ptr=NULL;
/* printf( "\n" );
printf( Name );
fflush( stdout );*/
/* Getting 'login' from QUERY_STRING */
tmp=LogIn;
ptr=strstr(QUERY_STRING,"login");
ptr+=6;
do{
*tmp=*ptr;
tmp++;
ptr++;
}while(*ptr!=38);
*tmp=0;
ptr=NULL;
/* printf( "\n" );
printf( LogIn );
fflush( stdout );*/
/***************************************/
/* Getting 'message' from QUERY_STRING */
tmp=Message;
ptr=strstr(QUERY_STRING,"message");
ptr+=8;
do{
if((*ptr==37)&&(*(ptr+1)==50)&&(*(ptr+2)==48)){*tmp=32;ptr+=2;}
else{*tmp=*ptr;}
tmp++;
ptr++;
}while(*ptr!=38||ptr==NULL);
*tmp=0;
ptr=NULL;
/* printf( "\n" );
printf( Message );
fflush( stdout );*/
message=fopen("message.txt","a");
fputs("\n\n",message);
fputs("Name : ",message);
fputs(Name,message);
fputs("\nLogin : ",message);
fputs(LogIn,message);
fputs("\nMessage : ",message);
fputs(Message,message);
fclose(message);
/* Printing answer page */
FILE *page=fopen("mes_cgi_back_page.htm","r+");
char line[50]="";
char sim;
fpos_t pos;
do{
fgets(line,50,page);
printf( line );
fflush( stdout );
fgetpos(page,&pos);
sim=fgetc(page);
fsetpos(page,&pos);
}while(sim!=EOF);
#if TEST_MODE
while(!kbhit());
#endif
}
Snake
/***********************************************/
Take a look around , things gonna be my way // Limp Bizkit
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|