CGI basics

One of the more frequently asked questions I receive here at betips.net is „How do I set up a BeOS web server to do CGI?“ The answer to this is no different from setting up CGI on any other POSIX platform, unless you’re working with attributes, in which case there are other details to be aware of (see the TrackerBase page for more on that).
First of all you’ll need to be running a CGI-capable web server — anything but PoorMan will do (see RobinHood, or dinerApache is coming soon).
Once your server is up and running, create a cgi-bin directory in the server’s root — this will store all of your bash, perl, or other scripts to be executed by the server. CGI, by the way, stands for Common Gateway Interface — a CGI script can be written in any language — even compiled C or C++, though perl is by far the most common language used in CGI implementations.
The first line of your script always consists of the „magic cookie,“ and points to the interpreter for the language the script is written in. For example, here are the magic cookies you would use for bash and perl scripts, respectively:


Note that the magic cookie must include the full path to the interpreter, even if it’s already in your path.
You must make your scripts executable with the chmod command (if you want to do this graphically, you can use Chris Herborth’s SetPerms. Tracker add-on). If working from the command line, use:

chmod 755 filename.cgi
or
chmod a+x filename.cgi

The only other important thing to remember is that when you want results from the script returned as a web page, you must send the HTML header before you start spitting out HTML code. This will look like:

echo "Content-Type: text/html"

in a shell script, or

print "Content-type: text/html
" ; 

in a perl script.

 

Comments

No comments so far.

(comments are closed)

Kategorien

 
 
Blogroll
Resources