Global Procedures

Global Procedures offer users a way to write code that acts on all FoxWeb requests. There are two types of global procedures: The program fw_enter.prg is executed before FoxWeb scripts, while the program fw_exit.prg is executed after scripts are done. These files must reside in the Program Root directory for the virtual server receiving the current hit. If two or more virtual servers share the same program root, then they will also share the same global procedure files.


With every request, FoxWeb looks for a procedure called FW_ENTER.PRG in the Program Root directory. If it finds one it executes it before calling the script specified in the URL. FW_ENTER.PRG can be used in cases where the programmer wants to establish a common environment for user programs or globally change the outcome of requests based on different criteria. If FW_ENTER.PRG returns .F. then FoxWeb does not process the user procedure specified in the URL.

Here are some potential uses of FW_ENTER.PRG:

Establishment of a default environment:

FW_ENTER can contain commands that establish a global environment for user programs. It can establish environment settings, open tables, and initialize memory variables. Note: All memory variables must be declared as PUBLIC if they need to be preserved for use by user programs.

Restriction of access to certain areas

FW_ENTER can restrict access to different programs, based on domain name or ip-address. The following code restricts access to the programs in the /customer path to everyone outside the domain 128.23.111.:

IF (LOWER(Request.PathInfo)='/customer/') .AND.;
        (NOT '128.23.111.' $ Request.ServerVariables("REMOTE_ADDR"))
    Response.Write('<H3>You Do Not Have Access to this Area</H3>')
    RETURN .F.

This technique can also be used to restrict access to programs in construction to everyone other than the company's internal staff.

Adjustment of URLs

Suppose that you moved a whole set of programs to a different directory, but there are still some users with bookmarks pointing to the old URL. You could include code that substitutes the old directory name with the new one:

Request.PathInfo = STRTRAN(LOWER(Request.PathInfo),'/old/','/test/')
Call of Plug-In programs

FW_ENTER can include commands to call Plug-In programs like the Browser Statistics Utility.


After executing each user program, FoxWeb looks for a procedure called FW_EXIT.PRG in the Program Root directory. If it finds one it executes it before sending output to the browser. The Post-Processor can be used in cases where the programmer wants to restore the default environment, modify the contents of buffered output, or increment statistic counts.

Here are some potential uses of the FW_EXIT.PRG:

Closing of data files

FW_ENTER can include custom code to close data files:

* If between 6am and 6pm, leave some files open,
* otherwise close them all for backup purposes

IF BETWEEN(SECONDS(),21600,64800)
    * Close DBFs that are not in this list
    FOR count = 1 TO 20
        USE IN M.count
    IF !EMPTY(DBC())

In order for this code to work, you must disable automatic file closing in the FoxWeb Configuration Screen

© Aegis Group