If you want to have any type of interactivity with your web visitors, you will need to learn how to set up a web form and CGI application. With these set up correctly, your users can send you email, fill out registration forms, fill out a survey and hundred more possibilities.
CGI stands for Common Gateway Interface. It receives data from your web page via the form tag, parses it as you wish and then returns another web page or passes data to whatever destination you wish. It is basically running a computer program on your web pages.
The FORM tag
Location is important
To run correctly, the CGI program needs to reside in a special directory so that the web server knows to execute the program rather than just display it as it would a web page. Under normal circumstances all CGI programs would reside in the web server’s CGI-BIN directory and be called from there. But, for security reasons, we can’t have a central location for all faculty, staff or students who might need to run a script on their web pages. Instead, we have provided the ability for you to run CGI applications from within your public_html directory. Learn how to set up the cgiwrap directory. If you are in charge of a project or organization’s web site, contact us to have a CGI program set up for you.
Speak the right language
Our web server is able to run these programming languages. The paths to the language files are in parenthesis. This location is usually needed by the script for the program to run. If you have need of an additional language, please contact us to request it.
- C and C++
- Java 1.7.0 (/usr/bin/java/)
- Perl 5.16.3 (/usr/bin/perl/)
- PHP 7.0.30 (/usr/bin/php/)
- Python 2.7.5 (/usr/bin/python/)
- Unix shell scripts
Tips on Scripts
UNIX, not Windows
When you edit your CGI scripts, remember that the program will be running on a Unix platform. This means that you shouldn’t use Windows text editors to edit your files because Windows tends to place the wrong line feed character at the end of each line and might create special characters such as “smartquotes”. Unix will not be able to read these correctly. CGI files should be simple ordinary text. You should either use a Unix text editor like VI or NANO or make sure your editor doesn’t create Windows line feeds or special characters.
Ask for Permission
Make sure your CGI file has the right permissions. You should log into a Unix prompt, “cd” to your public_html/cgi-bin/ directory and type chmod 755 filename where “filename” is the name of your CGI application. If your script doesn’t have the “execute” and “read” permissions set for “other”, then it can not be run via the web. Also, make sure that the cgi-bin directory has the proper permissions.
Test and then Test AgainIf it is possible, test your CGI application from the command line for errors. Any internal errors in your code will not appear on the web page. If this is not possible (for example, you need input from a form to run the script) then look into the language you are using for error checking utilities. For example, in Perl you can use this line:
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);to display errors in the browser window.
If you need additional information about your script’s errors, you are welcome to contact ETS and ask for a listing of the webserver’s error log files as they pertain to your program. Just make sure you give us the date and time of the error and the name and location of your script.
Beware of Idiots
Be careful in your choice of CGI applications. There are some CGI programs that are written poorly and could very well create security problems for the College of Engineering. The likelihood of such an occurrence is very low, but there is always a possibility. The cgiwrap method does a very good job of protecting the server from the majority of these attacks, fortunately. However, if your script is proven to be a security risk for the College of Engineering, we will be forced to take action to stop any attacks. This might mean we simply ask you to remove the program, or we might need to take ownership of the file to disable it. The action taken will completely depend on the circumstances involved and we trust that you understand the reason for such a policy.
Do not create a web business using the College of Engineering’s web servers and a “shopping cart” CGI application. Such activity is prohibited by Colorado State University’s policies concerning the use of the University’s computer equipment. Read the Acceptable Use Policy (AUP) for Computing and Networking Resources at Colorado State University