By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,251 Members | 2,764 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,251 IT Pros & Developers. It's quick & easy.

display a html file

100+
P: 254
I have a html file contains a form asking user to select a choice and press enter to pass the data to server.

In server there, i have a cgi script(C language) that accepts the input from browser and then output a html page to browser.

The browser should open the page, but it didn't, instead, it prompt me to save the file(.cgi file i requested in form method)....

how that happens?
i want to display the html file that the script output to browser, not to save that file.

here is my script:
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. extern void  cgiGetInput();
  4. extern char *cgiGetValue(char *name);
  5. extern char *cgiGetName();
  6. extern void cgiReset();
  7. extern char *cgiGetKeyword();
  8.  
  9. /** Turn debuggine on or off **/
  10. int Debug = 0;
  11.  
  12. int main(int argc, char *argv[], char *env[]) {
  13.  
  14.     if(Debug){
  15.         fprintf(stderr, "Start of script\n");
  16.     }
  17.     cgiGetInput();
  18.  
  19.     /*
  20.     **    print out Version Choice Form page to browser
  21.     */
  22.  
  23.     // output the content type
  24.     printf("Content-Type: text/html\r\n");
  25.  
  26.     printf("\r\n");
  27.  
  28.     printf("<html><head><title>Version Choice Form</title></head>\n");
  29.     printf("<body>\n");
  30.  
  31.     printf("<p class=\"title\">Versoin Choice Form!!</p>");
  32.  
  33.     printf("The choice you made is %s", cgiGetValue("sound"));
  34.  
  35.     printf(
  36.         "<form method=\"POST\">"
  37.         "<input type=\"radio\" name=\"version\" value=\"original\" checked /> Original Version\n"
  38.         "<input type=\"radio\" name=\"version\" value=\"dynamic\" /> dynamically-created \"echo\" version\n\n"
  39.         "<input type=\"submit\" name=\"retrieve\" value=\"Retrieve Sound\" />"
  40.         "</form>"
  41.         );
  42.  
  43.     printf("</body></html>");
  44.     return 0;
  45. }
  46.  
html file
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC
  2.           "-//W3C//DTD HTML 4.01 Transitional//EN"
  3.           "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml" lang="EN">
  5. <head>
  6. <title>Select a sound</title>
  7. </head>
  8.  
  9. <body>
  10. <h1>Forms Page 1</h1>
  11. This page is an example of a forms page with a submit button. This is the
  12. first of 2 forms pages. Both pages call the same script. How does the
  13. script know which page has been used?
  14. <p />
  15. <form action="assign2.cgi" method="get">
  16.  
  17. <p />
  18. Select a sound you want to hear :<br />
  19. Train sound<input type="RADIO" name="sound" value="train" checked />
  20. Yes sound <input type="radio" name="sound" value="yes" />
  21.  
  22. <p />
  23. <input type="RESET" value="Reset" />
  24. <input type="SUBMIT" value="Next" name="form1" />
  25. </form>
  26. </body> </html>
  27.  
it should display that dynamic html page, how come browser ask me to save that file?
ps: i use Mozilla Firefox browser.

please anyone help...
urgent here..
thanks alot.
Nicky Eng.
Jan 16 '07 #1
Share this Question
Share on Google+
11 Replies


Expert 100+
P: 1,892
Is this an HTML question? Looks more like a C question I will copy this thread to that forum.
Jan 16 '07 #2

100+
P: 254
Is this an HTML question? Looks more like a C question I will copy this thread to that forum.
i'm not sure i should post here or in C subforum, because i'm not sure my question involves which side, maybe both because its about HTTP reponse since cannot output the html file i generated dynamically in the script.

thanks for the help.
Nicky Eng
Jan 16 '07 #3

drhowarddrfine
Expert 5K+
P: 7,435
Your code/server needs to output the header for the browser.

EDIT: I see you are outputting it properly. Get the Firefox extension TamperData or HTTPSomething(forgot the exact name) so you can view what is actually sent/received.
Jan 16 '07 #4

drhowarddrfine
Expert 5K+
P: 7,435
LiveHTTP Headers

In addition, I think Content-Type is supposed to be Content-type with a lower 't' but I don't know if that will cause the problem.
Jan 16 '07 #5

Expert 100+
P: 1,892
i'm not sure i should post here or in C subforum, because i'm not sure my question involves which side, maybe both because its about HTTP reponse since cannot output the html file i generated dynamically in the script.

thanks for the help.
Nicky Eng
I've copied the thread to the C forum. Try Dr's suggestion let us know if it works out.

Aric
Jan 16 '07 #6

drhowarddrfine
Expert 5K+
P: 7,435
I just tried the code you have above, without the cgi stuff, and it all works so the cgi calls might be causing this problem.

Can you do the cgiGetInput followed by sending the page? I wouldn't know.

I'll follow this over to the C forum.
Jan 16 '07 #7

100+
P: 254
......
how that happens?
i want to display the html file that the script output to browser, not to save that file.
....
As i said above. I dont think there is problem with cgi script, i just dont understand why firefox keep asking me to save the cgi script, here is the printscreen everytime i click on submit button, the address bar display "http://hostname/test3.cgi",
and then it prompt me this :



why?
Jan 17 '07 #8

drhowarddrfine
Expert 5K+
P: 7,435
Because the .cgi mime is not something a browser handles. .cgi is executed on servers, not in browsers, so it assumes it is a downloadable file.
Jan 17 '07 #9

100+
P: 254
Because the .cgi mime is not something a browser handles. .cgi is executed on servers, not in browsers, so it assumes it is a downloadable file.
so what can i do to fix that?

make changes on code in main configuration file of my server(apache) ?

i need to fix this asap, because i wanna continue my work
Jan 17 '07 #10

100+
P: 254
my access_log file contain the below line when i send the form to server.
Expand|Select|Wrap|Line Numbers
  1. xx.xx.xxx.xxx - user1 [18/Jan/2007:04:51:57 +1000] "GET /ass2/members/assign2.cgi?sound=train&form=Next HTTP/1.1" 200 16069
  2.  
So that means it success sent the query string, but cannot execute my cgi script?
Jan 17 '07 #11

100+
P: 254

Thanks for DR's help.

I fix the problem by setting the per-directory configuration file(.htaccess file).
I missed some directives for executing cgi script in this particular directory:
Expand|Select|Wrap|Line Numbers
  1. Options +ExecCGI
  2. AddHandler cgi-script cgi
  3. ...
  4. ...
  5.  
thanks alot tho.
from
Nicky Eng
Jan 17 '07 #12

Post your reply

Sign in to post your reply or Sign up for a free account.