# CHAPTER 8: Session-based Application

## 8.1 Introduction

Session based applications can be build by replacing the `ehsql.cgi` program with `ehlink.cgi`. A session base application simulates a permanent link to the RDBMS server. This allows transaction processing to be carried out over numerous client server communications; with `ehsql.cgi` transaction can only be carried out within the context of single request to the HTTP server - ie in a single HTML page.

Except for log-on, log-off, and the specific transaction commands, applications built with `ehsql.cgi` and `ehlink.cgi` are syntactical equivalent. Therefore, if you build your applications using relative URL links (so the CGI itself is not specified in most pages), it is possible to toggle an application between the two modes of operation.

The session base system has two modes of log-on:

- Automatic
- Prompted

With automatic log-on the system uses the same log-on information as the `ehsql.cgi` program: typically the `DEFAULT_USER` and `DEFAULT_PASSWORD` resource variables in the `ehtml.ini` file.

The syntax for an automatic log-on is:

       <A HREF="/My-bin/ehlink.cgi/app_page.ehtml?openconnect+db_hostname+db_logical_name">

WHilst the syntax for the prompted log-on is:

       <A HREF="/My-bin/ehlink.cgi/app_page.ehtml?connect+db_hostname+db_logical_name">

With the prompted log-on the system will check whether the client is already connected to the specified data source, and if not it will prompt the client for log-on information (username and password).

A session based link will timeout after 15 minutes of inactivity. The timeout period can be changed by setting the `EH_LINK_TIMEOUT` resource variable.

## 8.2 Creating Log-on Form

The default layout for the log-on form is located at `$MSHYPERPATH/resources/html/connect.htm`.

If you wish to contruct you own log-on form. You can either replace this page, or create a new page called `connect.htm` in the same directory as your application page.

The action of the form should call the first page of the application, and the first three parameters of the action URL should be:

       ?verify+hostname+logical_database_name

As well, the form must allow the user to input both username and password. The names of these fields must be `eh-uid` and `eh-password`.

If you want to write such a page, the best idea is to copy the default page from `$MSHYPERPATH/resources/html/connect.htm` and modify it - making sure you don't change the form content.

## 8.3 Transaction Control

Transactions are controlled by using the `TYPE="TRANSACTION"` of the `ehsql:writer` option of the `EXECUTE` tag.

## 8.4 Shutting Down the Connection

Within your application you may choose to have a button which allows the user to explicitly end the session when ready to leave. In the previous example, this is done by providing a link to the following URL:

       http://bob:8080/My-bin/ehlink.cgi?disconnect+all

This will shut down all connections opened by `ehlink.cgi` for that particular user. There is currently no command to shut down an individual connection.