Creating a Web page counter

Date:Archived
Product/Release:LANSA for the Web
Abstract:You can create Web page counters that can be used with each Function
Submitted By:Doug Boyling, LANSA Sydney Senior Consultant

A graphical Web Page Counter can be easily created to record how many people have been to a site. This could also be a counter of the number of "requests for this page" which would include people that press reload/refresh and people who go to the page then move on to another page but come back. It all depends on the requirements of the user.  The difference is that the first counter described is effectively a Hits counter and the later is more like a Page Served counter. Either style can be used with any function.

To setup a Web Page Counter, all that is required is the production of a very simple RDML Program and the creation of a AUTOALP system variable to store the number of hits on a page. The use of images (.GIFs or JPEGs etc) requires a little more work, as described in the rest of this tip.

The following RDML Program uses the variable WEBCNT to store the number of hits. This is variable then broken up into individual numbers using separate variables WC1 through to WC6. A Visual Page Component called WEBCNT has been created in LANSA for the Web to display the appropriate image for each individual number in the variables WC1 through to WC6.

The RDML FUNCTION command with OPTION(*HEAVYUSAGE) is used so that the Page counter is incremented only when the Function is started again (ie a Hits counter). Without this option the Page Counter would be incremented every time that Page is reloaded using the Reload button on the Menu bar of the browser or when the Web user revisited the page in the same "session" (ie Page Served counter).

* ********* Beginning of RDML commands **********
FUNCTION OPTIONS(*DIRECT *HEAVYUSAGE)
DEFINE FIELD(#WC1) TYPE(*CHAR) LENGTH(1) DECIMALS(0) TO_OVERLAY(#WEBCNT 1)
DEFINE FIELD(#WC2) TYPE(*CHAR) LENGTH(1) DECIMALS(0) TO_OVERLAY(#WEBCNT 2)
DEFINE FIELD(#WC3) TYPE(*CHAR) LENGTH(1) DECIMALS(0) TO_OVERLAY(#WEBCNT 3)
DEFINE FIELD(#WC4) TYPE(*CHAR) LENGTH(1) DECIMALS(0) TO_OVERLAY(#WEBCNT 4)
DEFINE FIELD(#WC5) TYPE(*CHAR) LENGTH(1) DECIMALS(0) TO_OVERLAY(#WEBCNT 5)
DEFINE FIELD(#WC6) TYPE(*CHAR) LENGTH(1) DECIMALS(0) TO_OVERLAY(#WEBCNT 6)
DEFINE FIELD(#IMGTYP) TYPE(*CHAR) LENGTH(4) DECIMALS(0) DEFAULT(‘''GIF''')
DEFINE FIELD(#WEBCNT) TYPE(*CHAR) LENGTH(6) DECIMALS(0)
CHANGE FIELD(#WEBCNT) TO(*AUTOALPnnxxxxxxxxx)
DISPLAY FIELDS((#WEBCNT))
* ********* End of RDML commands **********

This function will show the counter on a screen by itself. To implement simply include this logic and these fields in an application or with a little more effort set it up as an external function that is called and exchanges the values back.

Appropriate images are necessary to be able to serve them to a browser, a suitable set does come with Commerce Server/400 but there are many other sites and companies that sell or distribute royalty free images of the numbers 0 through 9. Make sure that they are placed in the correct directory (most often /LANSA/IMAGES in the IFS).

The following Web Component also needs to be setup so that the appropriate images are shown for each digit in the counter:

WEBCNT - Visual Page Component

<CENTER>
<TABLE border=0 cellpadding=0 cellspacing=0>
<TR>
<TD><IMG SRC="/img/<RDML MERGE="WC1">.<RDML MERGE="IMGTYP"></TD>
<TD><IMG SRC="/img/<RDML MERGE="WC2">.<RDML MERGE="IMGTYP"></TD>
<TD><IMG SRC="/img/<RDML MERGE="WC3">.<RDML MERGE="IMGTYP"></TD>
<TD><IMG SRC="/img/<RDML MERGE="WC4">.<RDML MERGE="IMGTYP"></TD>
<TD><IMG SRC="/img/<RDML MERGE="WC5">.<RDML MERGE="IMGTYP"></TD>
<TD><IMG SRC="/img/<RDML MERGE="WC6">.<RDML MERGE="IMGTYP"></TD>
</TR>
</TABLE>
</CENTER>