123

How to Process CGI Forms with Euphoria and Xitami

Simple, Powerful CGI for Free

Mike Wever
Xitami is a simple, yet powerful, free web server from the iMatix corporation. Euphoria is a simple and powerful free programming language created by Rapid Deployment Software. The two of them can work very well together to provide CGI functionality for your web site at no cost.

This tutorial assumes that you have a basic knowledge of the Xitami web server and the Euphoria programming language, as well as a familiarity with CGI programming. If this is not true for you, be warned that some of the following tutorial may be harder to understand. The tutorial is based on a system using Xitami version 2.5c2 and Euphoria version 3.1 on a computer running Windows XP SP2. Your system should use a similar or newer configuration.

Set up the Xitami Server

The first step is to set up Xitami to recognize Euphoria programs. This is done by setting up filters. Go to the web-based Xitami control panel and select the Configuration option. From there, select the Filters page from the navigation links along the top.

Set up one or more new filters using the file extensions that you want to use for Euphoria files. In my example, I have used the default Euphoria extensions of .ex and .exw. The filters must point to the processor program EXWC, which runs as a Windows program in console mode. The other processors (EX and EXW) do not work correctly with Xitami. Make sure you save your configuration after adding the new filters.

While you are in the control panel, check the CGI page to ensure that your CGI options are set correctly. The options "CGI enabled" and "Use standard I/O" must both be checked.

Restart your web server after making these changes. Once the server has started back up, it will be ready to process Euphoria programs.

Write a Euphoria CGI Program

See the sample program I have provided to get an idea of how to work with CGI in Euphoria. This program accepts data sent with the GET method and displays the method and the data on the web page.

Use the getenv() command to find your variables. There are a whole range of environment variables available to a CGI program, but the two most important are REQUEST_METHOD and QUERY_STRING. These will allow you to get the data (if any) that was passed to your program.

If your program was called via the GET method, your variables will be in the environment variable QUERY_STRING. If it was called using the POST method, your variables will be in the standard input (file 0) instead. (If you check the standard input when the program was called with GET, you will find the source code for your program.)

The data that goes back to the user is written to the standard output (file 1) as you would expect. Make sure that whatever output you create contains proper HTTP headers and a blank line separating the headers from the actual output.

Start with the sample program I've provided. Place the program in your webpage directory and call it from your web browser. You should see the values of the REQUEST_METHOD and QUERY_STRING printed on the page. If not, make sure that you have entered the program exactly as provided, all of the Xitami settings are correct, and the web server was restarted after making changes.

Once you have it working, you can expand the program to do whatever you have in mind. You will soon find that Euphoria's simple data handling and powerful abilities are well suited to CGI processing.

Published by Mike Wever

Mike Wever is a computer expert, sometimes video producer, and editor of a small press magazine called Wanderings.  View profile

The Xitami webserver was named by reversing Imatix, the name of the company that developed it.

To comment, please sign in to your Yahoo! account, or sign up for a new account.