Tutorial 1

 
Web Hosting
EziHosting provides fast, reliable web hosting solutions in Australia for both business and web developers.
Check it out what we have to offer...
 
Add Your Link
You can add your web site's link to the EziDirectory.
This will increase your site's traffic and link popularity!
Learn more...

 
Domain Names

Web Design
We specialise in Australian Web Design.
The EziHosting team can design your web site in days.
Contact us today for a free consultation and quote.

EziHosting is proud to be a corporate World Vision Sponsor - find out more...

Find out more about your secure certificate here.
Security and privacy issues
Earn 50¢
per click!
Become an
affiliate!

  Do you need
Technical Support?

Home

WEB HOSTING
Web Hosting Australia

F.A.Q.

EziSupport

Control Panel

Dedicated Servers

Special

 

DOMAIN NAMES
Australian Domain Names

TLDs

Int. Domains

Policy Stuff

 

DIRECTORY
Listing

Add your Site

 

MISCELLANEOUS
Web Design

Search Engine Optimisation.

Free Site Analysis

Toos & Tutorials

2 Free Carts!

EziMerchant

Secure Certificates

 

CONTACT US
Contact Details

E-Mail Us

 

1. A Basic CGI Program

#!/usr/local/bin/perl -w

print <<END_of_HTML;
Content-type: text/html

<HTML>
<HEAD>
<TITLE> Hello</TITLE>
</HEAD>

<BODY>
<H1> Hello</H1>
<P>
Hello World!
</P>
</BODY>

</HTML>
END_of_HTML

 

You can try this program for yourself by copying the text to your own public_html directory as basic.cgi, and make sure it is world readable and executable (chmod 755 basic.cgi) and uploaded in ASCII.

You can then run it by calling the following URL:
http://www.your-domain.com/basic.cgi (or whatever your domain name is)

Things to note

  • The program must be in your public_html directory or any directory under it.
  • Have the extension .cgi
  • Be executable (chmod 755).
  • There has to be a blank line between the Content-type line and the first <HTML> tag.
  • It must not contain any tabs or spaces.

Why does my CGI program not work?

Check syntax
The FIRST thing to do after writing code is to check the syntax is correct and you haven't made any basic mistakes (such as missing semicolons at the end of lines).
At the command prompt, type perl -c myprogram.cgi

Content-type: header
The most common error in beginners' CGI programs is not properly formatting the output so the server can understand it. The HTTP header is very important and you should understand it before progressing.

If you are really stuck as to why your program doesn't work, try the CGI: why things don't work home page. The most common problem is extra whitespace (spaces, tabs, hidden <CR> tags, etc)

Error Logs
All accesses to the server are logged. If a program fails, an entry will also be made in the error log. If you run the perl program with the -w switch, you will get extra warnings to help you debug any problems.
Your web server logs can be found through the control panel (EziHosting clients only).

CGI:Carp
You can get your CGI program to output any errors to the browser window by using the CGI::Carp module. Just add the following line near the top of any code...

use CGI::Carp qw(fatalsToBrowser);

This module arranges to send a minimal HTML page to your web browser in the event of a fatal runtime or compile error.

Ok, ready for the next step...
Back - Next

We hope this tutorial was helpful. If you like, you can link to our tutorials from your web site. Just use the following code:

<a href="http://www.ezi-hosting.com/tutorials.htm">Free Scripting Tutorials from EziHosting</a>

 

 

Web Hosting Australia Monthly Special


At EziHosting, the Australian Web Hosting company,
we strive to become your internet technology partner
for the long run...

© 2003 EziHosting Australian Web Hosting - All Rights Reserved