c programs for web scipts

Started by
2 comments, last by Anti-dentite 23 years, 4 months ago
Need a bit of help here, I''m trying to write a simple imange/banner rotation program in c for a website I''m working on. My question is, how I do I get the program to accept the input from the user? So, lets say for example, that the user wanted to view the next image and clicked on the link, it would send the info to my server, but how I do I get the c program to accept the information and then send it back? Oh, and I"m using borland c by the way, yup, it sucks but I''m stuck with it for now. Thanks, Anti-dentite
Advertisement
I think you''re looking at an ActiveX control here. You can''t just put C code right in the browser and execute it. Writing an ActiveX DLL can be a daunting task, and you''ll want to get it signed (expensive) if you want it to be secure for the users.

Depending on your situation, it sounds like maybe you could get away with a Java applet, scriptlet, or maybe even just DHTML.
no, I don''t want to do anything like a java applet. I want to write a cgi script using c. I just don''t know how to get the program to accept the user input (such as when he enters a form) or send anything back.
The information output by your form will be loaded as environment variables on the server. You can query these with getenv(). When you use GET for your form, the arguments come in explicitely in the QUERY_STRING environment variable. When you use POST, they come in on stdin. To save you some trouble, here''s a piece that should handle the task:

          char *method = getenv("REQUEST_METHOD");        if(!method) method = "";        if(!strcmp(method,"POST")) { //assume application/x-www-form-urlencoded                char *len_str = getenv("CONTENT_LENGTH");                if(!len_str) len_str = "";                int len = atoi(len_str);                char *buf = (char *)malloc(len+1);                if(fread(buf,1,len,stdin) != len) {                        fprintf(stderr,"Error reading POST data (length=%d).\n",len);                }                buf[len] = 0;                SetQueryString(buf);                free(buf);        }        else SetQueryString(getenv("QUERY_STRING"));   


Where SetQueryString() is some function you can use to parse the arguments. They will come in like: arg1&arg2&arg3 ... etc.

HTH

This topic is closed to new replies.

Advertisement