About usContact usSite help
Quick links
Search this site

Using cgi-bin

This section will tell you all you need to know about using cgi scripts on Demon's commercial web solution.

The Basics
Getting Your Scripts to Work
Calling Your Scripts from Your html
Debugging Your Scripts
cgi FAQ

Basics

All cgi scripts that you use with your Commercial Web Space, must be written in Perl 4 or 5 (we support 5.004). These files must be uploaded as ASCII (PC), Plain Text (Mac); so they are in Unix format on the server. So that the script is executable you must change the permissions of the file, this is done using the chmod command.

Getting your scripts to work

To change the permissions of the script, you will need to telnet to your web space (using the same details as with FTP). Once you are connected, this will provide you with a $ sign where you type the UNIX commands as detailed in the Using UNIX section.

To set the permissions for your script so that it can be run by users browsing your pages, you need to follow these steps:

  • Change to the cgi-bin directory using cd, cd cgi-bin
  • Use the chmod command on the script, changing the permission to 705, chmod 705 my-script.pl
  • Type
ls -l

to check to see if you have been successful.

Here's an example

$
$ cd cgi-bin
$ ls -l
total 2
-rw-r--r-- 1 3149 102 11 Dec 22 11:25 my-script.pl
$ chmod 705 my-script.pl
$ ls -l
total 2
-rwx---r-x 1 3149 102 11 Dec 22 11:25 my-script.pl
$

[where -rwx---r-x represents the permission settings for your file. You are interested in the last 3 characters. For your script to run from your web pages you need to make sure the 'x' or execute bit is set].

Calling your scripts from your html

To refer to your cgi scripts from within a html document you should use:

http://cgi.www.yourdomain.co.uk/cgi-bin/www.yourdomain.co.uk/your-script.pl

If you need to reference your docs directory from your script then use:

/docs/www.yourdomain.co.uk/your-file

Debugging your scripts

Our web servers include a special function which allows you to produce debug output from your perl scripts via the web. If you find you are having problems with your perl cgi script, rename the script with the prefix xx- and then point your browser to the new name of the script. This then redirects the messages that would go to STDERR, to STDOUT, thus enabling you to receive some form of debugging information.

Note: before trying this you may want to check the FAQ.

For example, if you had a broken perl script in your cgi-bin directory again called my-script.pl, you would do the following -

  • rename your script to xx-my-script.pl
  • refer to it in your browser using,
  • http://cgi.www.yourdomain.co.uk/cgi-bin/www.yourdomain.co.uk/xx-my-script.pl
  • this would then display output to the browser, including STDERR and STDOUT.

In general terms, the more important part of the debug page is to look at the section after 'Output of script follows:' which displays the information that the actual script would output. For example, a script containing -

#!/bin/perl
print "Content-type: text/html\n\n";
print "This is an example.\n";

would result in the following at the bottom:

Output of script follows:
=====================================================
path: '/cgi-bin/www.yourname.co.uk/xx-my-script.pl'
argv[0]: 'xx-my-script.pl'
argv[1]: '<NULL>'
Content-type: text/html

A full example of the output can be found here.

cgi FAQ

Commonly asked questions regarding using cgi scripts and their answers can be found in the Developing Your Site Further FAQ.


Helpdesk Tel: 0845 272 2555 for Commercial Web support
   e-mail: websupport@demon.net
Autoresponder: support@demon.net; Minicom: 0845 272 2445


More Help





*