I have a homework assignment that I am supposed to write a http server that is supposed to process an input given in a form on my index.html page. To do this I have a form that uses the POST action and links to a cgi file. The problem that I am having is linking to my cgi file. My index file and the cgi file are in the same folder so my form looks something like this:
<form action="test.cgi" method="POST">
Username: <input type="text" name="user" />
<input type="submit" value="Submit" />
</form>
When I connect to my server I connect to: localhost:PORT which gives me the index file and when I hit the submit button I get linked to localhost:PORT/test.cgi
In my mind this should directly link me to my cgi file and everything should work. I know that this must be because I do not understand how the server organizes the files on my computer. Could someone explain to me how this works?
If I didn’t post some vital information just let me know and I will edit the post as soon as possible.
Since you are writing the HTTP server, you can define the ‘rules’ of CGI processing 🙂
Apache, for example, by default requires one to place CGI scripts in cgi-bin directory to enable their execution. This is all configurable via httpd.conf – so user can disable CGI or specify another directory for CGI scripts via the configuration file – you may choose to do something similar.
Also note that the file extensions for CGI files are typically test.pl (for perl scripts) and the server usually does a fork/exec of the specified script file
http://httpd.apache.org/docs/2.0/howto/cgi.html is a good reference