# Serving Web Pages: CGI Integration¶

The ginger-cgi executable runs the GVM as a CGI script. You use it just like the ginger-script tool, except that the HTTP parameters are automatically read in and can be processed by the script.

CGI scripts access their environment in two ways:

• Via environment variables. Use the \${variable} syntax to do that.
• Via the request parameters. Use the cgiValue system function to request these.

## Example script¶

Here’s a very simple “hello_world.cgi” script:

#!/usr/local/bin/ginger-cgi -gcommon

print( "Content-type: text/html\r\n\r\n" );
println( "Hello, %p!", cgiValue( "name" ) );


And here is the result:

steve% ./hello_world.cgi
Enter querystring or type 'i' for interactive mode'
name=Steve
Content-type: text/html

Hello, Steve!


## Using Elements¶

One of the main uses of elements is generating XHTML output. For example, an HTML version of Hello World would look like this.

#!/usr/local/bin/ginger-cgi -gcommon

print( "Content-type: text/html\r\n\r\n" );
<html>
<body>
"Hello, %p!".stringf( cgiValue( "name" ) )
</body>
</html>


Notice how the character data is represented by a string. In fact you can use any item, which will be printed out using XHTML escaping.

And here is the result:

steve% ./hello.cgi
Enter querystring or type 'i' for interactive mode'
name=Steve
Content-type: text/html

<html><body>Hello, Steve!</body></html>


Note that applying the print functions to an element will generate proper XHTML output with correctly escaped characters.

## Future Enhancements¶

The CGI support is minimal at the time of writing. This is because our plans for enhancing this facility depend on a GVM feature that isn’t stable as yet, called