|
Overview
Here is a very simple script that needs no changes for it to work on a Spaceports CGI-BIN
account. Those of you using other hosts should only need to change the path to Perl. It
is possible that you may also need to remove the second and third lines if they do not
have the CGI.pm module installed (most do).
Some of the beginners are still tearing their hair out and finding out that the problem is one
(or both) of the following:-
- Not uploading in ASCII mode.
- Not setting permissions correctly.
To help you practice getting those first two right before trying more advanced scripts, here is
a simple script with no need for changes to be made for it to run at Spaceports:-
practice.cgi
#!/usr/bin/perl
use CGI;
use CGI::Carp qw/fatalsToBrowser/;
# practice.cgi -- use to practice uploading and permission setting
print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE>Not the Spaceports Page!</TITLE>\n";
print "</HEAD>\n";
print "<BODY>\n";
print "<CENTER>\n";
print "<H1>It's <U>not</U> the Spaceports Page!</H1>\n";
print "<H2>I managed to upload in ASCII mode and CHMOD 755</H2>\n";
print "<HR>\n";
print "<P><SMALL>(And I still have most of my hair)</SMALL></P>\n";
print "</CENTER>\n";
print "</BODY>\n";
print "</HTML>\n";
Save that as practice.cgi then upload it in ASCII mode anywhere inside the
public_html folder in your CGI-BIN account and CHMOD it to 755. If you get that
right you will not see the Spaceports main page when you enter the URL.
Error trapping (to the browser) is built in.
Don't believe me? Here's an example.
If you still see the Spaceports page, it must be the upload mode, the CHMOD settings or you're
trying to call it with an incorrect path/filename. Remember, Spaceports uses a variant of the
UNIX operating system which means that filenames are case sensitive - Practice.cgi and
practice.cgi are not the same.
hello.cgi
Here is a slightly shorter, and more traditional version of the same script:-
#!/usr/bin/perl
use CGI;
use CGI::Carp qw/fatalsToBrowser/;
# hello.cgi -- use to practice uploading and permission setting
print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<HEAD><TITLE>Hello World!</TITLE></HEAD>\n";
print "<BODY>\n";
print "<CENTER><H1>Hello World!</H1></CENTER>\n";
print "</BODY>\n";
print "</HTML>\n";
This will be very familiar to those of you that worked your way through my earlier tutorial.
Save that as hello.cgi then upload it in ASCII mode anywhere inside the
public_html folder in your CGI-BIN account and CHMOD it to 755. If you get that
right you will see a page with the phrase 'Hello World!' on it when you enter the
URL. Error trapping (to the browser) is built in.
Again, if you still see the Spaceports page, it must be the upload mode, the CHMOD settings or
you're trying to call it with an incorrect path/filename.
|