display a html file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nickyeng
    Contributor
    • Nov 2006
    • 252

    display a html file

    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:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    extern void  cgiGetInput();
    extern char *cgiGetValue(char *name);
    extern char *cgiGetName();
    extern void cgiReset();
    extern char *cgiGetKeyword();
    
    /** Turn debuggine on or off **/
    int Debug = 0;
    
    int main(int argc, char *argv[], char *env[]) {
    
    	if(Debug){
    		fprintf(stderr, "Start of script\n");
    	}
    	cgiGetInput();
    
    	/*
    	**	print out Version Choice Form page to browser
    	*/
    
    	// output the content type
    	printf("Content-Type: text/html\r\n");
    
    	printf("\r\n");
    
    	printf("<html><head><title>Version Choice Form</title></head>\n");
    	printf("<body>\n");
    
    	printf("<p class=\"title\">Versoin Choice Form!!</p>");
    
    	printf("The choice you made is %s", cgiGetValue("sound"));
    
    	printf(
    		"<form method=\"POST\">"
    		"<input type=\"radio\" name=\"version\" value=\"original\" checked /> Original Version\n"
    		"<input type=\"radio\" name=\"version\" value=\"dynamic\" /> dynamically-created \"echo\" version\n\n"
    		"<input type=\"submit\" name=\"retrieve\" value=\"Retrieve Sound\" />"
    		"</form>"
    		);
    
    	printf("</body></html>");
    	return 0;
    }
    html file
    Code:
    <!DOCTYPE HTML PUBLIC
              "-//W3C//DTD HTML 4.01 Transitional//EN"
              "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="EN">
    <head>
    <title>Select a sound</title>
    </head>
    
    <body>
    <h1>Forms Page 1</h1>
    This page is an example of a forms page with a submit button. This is the
    first of 2 forms pages. Both pages call the same script. How does the
    script know which page has been used?
    <p />
    <form action="assign2.cgi" method="get">
    
    <p />
    Select a sound you want to hear :<br />
    Train sound<input type="RADIO" name="sound" value="train" checked />
    Yes sound <input type="radio" name="sound" value="yes" />
    
    <p />
    <input type="RESET" value="Reset" />
    <input type="SUBMIT" value="Next" name="form1" />
    </form>
    </body> </html>
    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.
  • AricC
    Recognized Expert Top Contributor
    • Oct 2006
    • 1885

    #2
    Is this an HTML question? Looks more like a C question I will copy this thread to that forum.

    Comment

    • nickyeng
      Contributor
      • Nov 2006
      • 252

      #3
      Originally posted by AricC
      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

      Comment

      • drhowarddrfine
        Recognized Expert Expert
        • Sep 2006
        • 7434

        #4
        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(f orgot the exact name) so you can view what is actually sent/received.

        Comment

        • drhowarddrfine
          Recognized Expert Expert
          • Sep 2006
          • 7434

          #5
          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.

          Comment

          • AricC
            Recognized Expert Top Contributor
            • Oct 2006
            • 1885

            #6
            Originally posted by nickyeng
            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

            Comment

            • drhowarddrfine
              Recognized Expert Expert
              • Sep 2006
              • 7434

              #7
              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.

              Comment

              • nickyeng
                Contributor
                • Nov 2006
                • 252

                #8
                Originally posted by nickyeng
                ......
                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?

                Comment

                • drhowarddrfine
                  Recognized Expert Expert
                  • Sep 2006
                  • 7434

                  #9
                  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.

                  Comment

                  • nickyeng
                    Contributor
                    • Nov 2006
                    • 252

                    #10
                    Originally posted by drhowarddrfine
                    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

                    Comment

                    • nickyeng
                      Contributor
                      • Nov 2006
                      • 252

                      #11
                      my access_log file contain the below line when i send the form to server.
                      Code:
                      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
                      So that means it success sent the query string, but cannot execute my cgi script?

                      Comment

                      • nickyeng
                        Contributor
                        • Nov 2006
                        • 252

                        #12

                        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:
                        Code:
                        Options +ExecCGI
                        AddHandler cgi-script cgi
                        ...
                        ...
                        thanks alot tho.
                        from
                        Nicky Eng

                        Comment

                        Working...