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:
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.
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.:
This technique can also be used to restrict access to programs in construction to everyone other than the company's internal staff.
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:
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:
FW_ENTER can include custom code to close data files:
In order for this code to work, you must disable automatic file closing in the FoxWeb Configuration Screen