Megan's Notebooks
MEGAN'S NOTEBOOKS // HTML Tags // SOURCES // CGI & FORMS // LINKS// HELP

Common CGI Script Errors


If none of the following helps, email me and I'll try to help.
  • What do I need to process cgi scripts?
A directory on your server that can run them. That directory must be ScriptAliased or ExecCGI-enabled. Your server administrator can tell you this.
  • What are all these weird ^M's in my script after I FTP'ed it?

Always use ascii or text, never binary mode to transfer your scripts to the server . If you still get ^M's edit them out with vi like this:

vi scriptname
:1,$s/^v^m//g Ctrl v Ctrl m
:wq

thatís a one not a ell, and Ctrl v Ctrl m

Macintosh files can be converted to UNIX-style files buy using the following command line on UNIX:

tr '\015' '\012' < oldfile.html > newfile.html


  • How do I make my scripts executable ?

On servers that allow CGI you must set the file permissions to 755.
chmod 755 scriptname

or, if you are using a ftp client that allows sending ftp commands try
site chmod 755 scriptname

See your local 'chmod(1)' man page if you need help with setting permissions.
man chmod


  • My script doesn't work!! I get a "malformed header error"!!
Try running your script from the command line. It should execute without errors. If it has errors fix them.
  • Ok, I have the script executing, but no data comes back!

1. The first line of your code (in perl anyway) should be

#!/usr/bin/perl

If that's not the location of PERL, try typing which perl at the command line, it will return the full path to perl on your server.

For a shell script it probably needs to be: #!/usr/bin/sh

2. You could be forgetting to send back headers.

This needs to be in any script that sends back any HTML:
print "Content-type: html/text\n\n";
#two new line characters needed, that's what the \n\n; is for in Perl.

If it's a shell script use:
echo Content-type: html/text
echo


  • I can't get my CGI to write to my file! Help!

If your cgi writes data to a file make sure that the files permissions are world writable.
chmod 666 filename


  • Final Tips
Check and recheck your paths. They must be right on. If you snagged the script straight of the net or someone e-mailed it to you (versus unpacking it from a tar or zip file) double check the syntax closely. If it doesn't run at the command line, it won't run on the web server.

Megan McCormack