| CGI Programs
|
Grove homepage
|
What are CGI programs?Many web pages are simply files containing static HTML. When a web browser requests a page from a web server, a file is copied back to the browser. Each time you load the page, it has exactly the same content. A CGI program lets you process data received from a client on the web server and dynamically generate HTML. The most common use is to process the data entered into a web form and to generate a response that's sent back to the browser. The way CGI programs are executed depends on the particular web server being used and the platform on which it's running. Grove is a Unix system running the Apache web server, so the way CGI programs are run is dictated by that environment and the way this particular web server is configured. A CGI program on grove can be written in any language that will run in a Unix environment. That includes C, C++, or any of the Unix scripting languages. The scripting language perl is available on grove and is a popular language for making CGI programs. This short note does attempt to explain everything you need to know about writing CGI programs to process web forms. You should consult one of the many books on that subject. This note does explain the two methods for running CGI scripts that are available on grove. Some warnings!On some web servers, CGI programs do not run in your account. Then usually run in a special "nobody" account. This means that CGI programs can't write files into your directory or damage existing files. This is not true on grove! CGI programs run as if you logged in and ran the program on your account. You have full access to the files in your directory and a carelessly written program could damage any of your files. When you have CGI programs in your web directory, they can potentially be executed from anywhere in the world. They will run in your account and could read or write any file in your directory. If improperly written, they can expose your account to accidental or malicious damage. You are responsible for what happens in your grove account. It's up to you to make sure that your CGI programs aren't used to violate any local, state, or federal laws, and that they do not violate local computer policies. See the document Policies for use of computers at UF. In short, writing CGI programs should be done cautiously and by someone familiar with the Unix environment and aware of the possible security problems associated with CGI programs. The .cgi file methodOn grove, we have enabled a feature of the Apache web server that lets you execute CGI scripts in your directory as if they were running in your account. The requirements are:
As a short example, use any text editor to create this file named hello.cgi in your public_html subdirectory:
#!/usr/bin/sh echo "Content-type: text/html" echo echo "<html>" echo "Hello" echo "</html>" Make sure that file is executable: chmod u+x hello.cgi You should be able to run it on grove under Unix and will display the HTML it will generate:
./hello.cgi You can execute this file using a URL like this: http://grove.ufl.edu/~your-username/hello.cgi If you've done everything correctly, your web browser should display the word "Hello". The cgiwrap methodAnother method for executing a CGI program in your web directory is to use a CGI program called cgiwrap. The requirements for this method are:
First, if you haven't already done so, create your cgi-bin subdirectory and set the proper permissions:
cd ~/public_html Then use any text editor to create the file named hello in the directory public_html/cgi-bin:
#!/usr/bin/sh echo "Content-type: text/html" echo echo "<html>" echo "Hello" echo "</html>" After creating the file, make sure it's executable: chmod u+x hello The URL to run the script using cgiwrap is: http://grove.ufl.edu/cgi-bin/cgiwrap/your-username/hello There are two advantages to using the cgiwrap instead of the .cgi file method:
|
Last Revision: Wednesday, 24-Aug-2005 13:03:03 EDT
|
HUB 132, E-mail: helpdesk@ufl.edu, Phone: (352) 392-HELP (4357) |
|