Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Anti-dentite

c programs for web scipts

This topic is 6590 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!