^^Web-form-to-email gateway

Now that you're able to run real, honest-to-goodness CGI scripts, let's make something useful: a Web-form-to-email gateway. This is probably one of the most common uses of CGI scripts, since it satisfies a very common need: You have an HTML form that you want users to fill out, and you want the contents of that form sent to you as an email message.


Dalla guida del sito tech-hosting

About CGI scripts

CGI (Common Gateway Interface) scripts are small programs used on many Web sites.

These programs are written in a computer language such as Perl, Tcl, C or C++, and they function between HTML pages and other programs on the Web server. For example, a CGI script could allow search data entered on a Web page to be sent to a database for lookup. It could also format the results of that search as an HTML page and send it back to the requester.

CGI scripts reside on your site, and they obtain data using environment variables that the Web server makes available to them.

For additional information about CGI scripts, see:

 

Uploading and running CGI scripts

You can upload and run CGI scripts to make your site interact with databases and other applications.

To upload and run a CGI script:

  1. Write or obtain the CGI script.

  1. Copy the script to the CGI directory on your site. If you are unsure of the name of your CGI directory, check the Configuration page. You can derive your CGI directory name from the Script Alias listed on the Configuration page. For example, if your Script Alias is cgi-bin, then your CGI directory name is /var/www/cgi-bin.

  2. Important: If you are on a Microsoft Windows system, you need to upload CGI scripts to your site through an FTP connection instead of through the File Manager. Further, when you upload through FTP, upload files as ASCII, so that hidden characters inserted into the CGI script by Windows are translated correctly. If these characters are not translated correctly, the CGI scripts do not work.

    If you are on a Linux system, you can upload CGI scripts to your site through the File Manager. Linux does not add hidden characters to files, so no translation is needed.

  1. Change the CGI script file permissions to the following settings:

  1. Open your Internet browser and in the Address field, enter the following URL:

http:// <web_server_name>/<script alias>/<script name>

Your CGI script runs. The results appear in the browser window

Environment variables used with CGI scripts

Environment variables are used in CGI scripts to represent information that is updated by the Web server when the scripts run. Using environment variables, scripts can get and use up-to-date information without having to store that information themselves.

In addition to the standard environment variables, the following three environment variables are available to all scripts on your site:

You can use these variables in your CGI scripts to avoid hard-coding directory path names. This ensures that path names are always correct, even if those path names change.