Tips for writing
portable CGI scripts The best CGI scripts are ones which require little or no configuration. By following these tips, you can insure that your CGI is portable, and will function properly even if the script is moved to another system or major changes are made to the environment. In such cases, these tips can help you reduce or eliminate the task of reconfiguration. Use the DOCUMENT_ROOT environment variable
/usr/home/yourname.com/file.txt ).
Use $ENV{'DOCUMENT_ROOT'} instead. This variable is of the
form: /usr/home/yourname.com/htdocs By using DOCUMENT_ROOT , your CGI script will not be sensitive
to changes in directory structure, or changes in domain name. The following
table shows the most common paths in terms of DOCUMENT_ROOT :
SERVER_NAME
environment variable
$ENV{'SERVER_NAME'} .Use this environment variable instead of hard-wiring the server name throughout the code: $myserver = $ENV{'HTTP_HOST'} || $ENV{'SERVER_NAME'}; By using SERVER_NAME , your CGI script will not be sensitive
if you change the domain name at a later date.SCRIPT_NAME
environment variable
$ENV{'SCRIPT_NAME'} :$myserver = $ENV{'HTTP_HOST'} || $ENV{'SERVER_NAME'}; $myurl = "http://$myserver$ENV{'SCRIPT_NAME'}"; By using SCRIPT_NAME , your CGI script will not be sensitive
if you choose to rename it at a later date.HTTPS
environment variable
http:// "
into the script, especially if you plan to use secure server. Use $ENV{'HTTPS'}
instead:$myserver = $ENV{'HTTP_HOST'} || $ENV{'SERVER_NAME'}; $myhttp = $ENV{'HTTPS'} ? "https://" : "http://"; $myurl = "$myhttp$myserver$ENV{'SCRIPT_NAME'}"; By using HTTPS , your CGI script will not be sensitive if
you choose to move it to/from a secure server environment.
For a list of environment variables available to your CGI script, please visit http://www.yourdomain.com/cgi-bin/env.pl which is pre-installed
into your /cgi-bin directory.
|
Main | Signup | Hosting | Design | Webmaster Resources | Contact Us!