Active Foxpro Pages 3: Userguide and Reference
Active Foxpro Pages 3: Userguide and Reference
First Edition
Published 2002
Copyright © 1997 - 2002 by ProLib Software GmbH
Active FoxPro Pages (AFP) connect the programming language Microsoft Visual FoxPro to the internet. The AFP
are acting like a script language (ie. PHP or ASP) in a web server. AFP can easily be used by any kind of
programmer and/or web designer.
Table of Contents
Welcome to the Active FoxPro Pages 3 .....................................................................................................i
This Book’s Audience ............................................................................................................................... ii
Organisation of This Book ...................................................................................................................... iii
Getting Examples from This Book ..........................................................................................................iv
Request for Comments ..............................................................................................................................v
I. Introduction ...........................................................................................................................................vi
1. What’s New? ..................................................................................................................................1
1.1. Feature List........................................................................................................................1
1.2. Requirements.....................................................................................................................2
1.3. License Model ...................................................................................................................2
1.4. Extensibility.......................................................................................................................4
2. Getting Started ...............................................................................................................................5
2.1. Hello World .......................................................................................................................5
2.2. What time is it?..................................................................................................................6
2.3. Access your data................................................................................................................6
2.4. Select your data .................................................................................................................7
3. Creating Dynamic Web Sites .......................................................................................................10
3.1. Event Handling ................................................................................................................10
4. Help ..............................................................................................................................................12
4.1. Installation .......................................................................................................................12
4.2. Interaction with the Web Server ......................................................................................13
4.3. Understanding the AFP Configuration ............................................................................14
4.4. Debug Mode ....................................................................................................................18
4.5. Error Handling.................................................................................................................18
5. AFP Applications .........................................................................................................................22
5.1. ISAPI Interface to the Web server ...................................................................................22
5.2. Hosts for the AFP Engine................................................................................................22
5.3. Hosts for the AFP Server.................................................................................................23
5.4. AFP 3.0 ControlCenter....................................................................................................24
6. Plugins..........................................................................................................................................30
6.1. C24 - AFP 2.4 Compatibility...........................................................................................30
6.2. DirectCall - Code-based Programming ...........................................................................33
6.3. Crypto - Secure your data................................................................................................33
6.4. Create your own Plugins..................................................................................................34
II. Reference .............................................................................................................................................38
7. Objects .........................................................................................................................................39
App-Object .............................................................................................................................39
File-Object..............................................................................................................................39
Path-Object .............................................................................................................................40
Request-Object .......................................................................................................................41
Response-Object.....................................................................................................................42
Server-Object..........................................................................................................................43
Session-Object........................................................................................................................44
8. Properties .....................................................................................................................................46
cCache-Property .....................................................................................................................46
iii
cCommon-Property ................................................................................................................46
cData-Property........................................................................................................................47
cFile-Property .........................................................................................................................48
cID-Property ...........................................................................................................................48
cLocation-Property .................................................................................................................49
cLog-Property.........................................................................................................................50
ContentType-Property ............................................................................................................51
Cookie-Property .....................................................................................................................51
cRoot-Property .......................................................................................................................52
cSession-Property ...................................................................................................................53
cVirtualLocation-Property ......................................................................................................54
Expires-Property.....................................................................................................................54
9. Methods........................................................................................................................................57
Abandon-Method....................................................................................................................57
AddExtension-Method ...........................................................................................................58
AddCookie-Method................................................................................................................59
AddHeader-Method ................................................................................................................60
BinaryWrite-Method ..............................................................................................................61
Body-Method..........................................................................................................................62
Call-Method............................................................................................................................63
Clear-Method..........................................................................................................................65
Clone-Method.........................................................................................................................66
CookieDate-Method ...............................................................................................................67
Cookies-Method .....................................................................................................................68
CreateSessionID-Method .......................................................................................................69
DoCmd-Method......................................................................................................................69
Document-Method..................................................................................................................70
Execute-Method......................................................................................................................71
Form-Method..........................................................................................................................71
GetCacheName-Method .........................................................................................................73
GetCookieHeader-Method......................................................................................................74
GetLocation-Method ..............................................................................................................75
GetSessionCookie-Method.....................................................................................................76
GetSessionData-Method.........................................................................................................77
GetSessionFileName-Method.................................................................................................78
Header-Method.......................................................................................................................79
HTMLDecode-Method...........................................................................................................80
HTMLEncode-Method ...........................................................................................................81
HTTPCookie-Method.............................................................................................................82
IsNew-Method ........................................................................................................................83
MakePath-Method ..................................................................................................................84
MapPath-Method ....................................................................................................................85
MultiPart-Method ...................................................................................................................86
NewSession-Method...............................................................................................................88
QueryString-Method...............................................................................................................88
Redirect-Method.....................................................................................................................90
Relative-Method .....................................................................................................................91
ReNew-Method ......................................................................................................................92
iv
Reset-Method .........................................................................................................................93
Reset-Method .........................................................................................................................94
Reset-Method .........................................................................................................................95
ResolveRelative-Method ........................................................................................................96
ServerVariables-Method .........................................................................................................97
SessionID-Method..................................................................................................................99
SetSessionData-Method .......................................................................................................100
Timeout-Method ...................................................................................................................101
Transfer-Method ...................................................................................................................102
URL-Method ........................................................................................................................103
URLDecode-Method ............................................................................................................104
URLEncode-Method ............................................................................................................105
Version-Method ....................................................................................................................106
Write-Method .......................................................................................................................107
III. Appendixes.......................................................................................................................................109
A. Multi-thread Restrictions of VFP..............................................................................................110
A.1. Unsupported commands in AFP multi-threaded mode ................................................110
A.2. Disabled commands in multi-threaded mode ...............................................................112
B. AFP License Agreement ...........................................................................................................114
B.1. License ..........................................................................................................................114
B.2. Copyright ......................................................................................................................114
B.3. Other restrictions...........................................................................................................114
B.4. Validity..........................................................................................................................114
B.5. Contact us .....................................................................................................................115
Glossary ..................................................................................................................................................116
Index........................................................................................................................................................120
v
List of Tables
6-1. AFP 2.4 - system variables.................................................................................................................30
6-2. AFP 2.4 - system methods..................................................................................................................33
A-1. Unsupported commands in AFP multi-threaded mode ...................................................................110
A-2. Disabled commands in multi-threaded mode ..................................................................................112
List of Figures
4-1. By accepting the License Agreement you are able to install the AFP ...............................................12
4-2. Select your Destination Path ..............................................................................................................12
4-3. Finally Finished - Additional information needed? ...........................................................................13
4-4. Configure IIS - Home Directory dialog..............................................................................................14
4-5. Configure IIS - Configuration dialog..................................................................................................14
4-6. Request an AFP document below virtual tree ....................................................................................18
4-7. Standard Error Report - Windows Event Log ....................................................................................19
4-8. Plain Errorlog File ..............................................................................................................................19
4-9. Detailed HTML Feedback - Red Screen of Death .............................................................................20
5-1. AFP 3.0 Desktop Application with Quick Launch.............................................................................23
5-2. The AFP 3.0 ControlCenter................................................................................................................24
5-3. Status overview of running AFP instances.........................................................................................24
5-4. Path declarations.................................................................................................................................25
5-5. Server related specifications for the AFP engine ...............................................................................26
5-6. Sessionmanagement - the easy configuration.....................................................................................27
5-7. Build Log needed?..............................................................................................................................27
5-8. Controlling the Debug options of the AFP Engine ............................................................................28
5-9. Specifying additional Plugins.............................................................................................................28
5-10. Entering the License informations and Activation key ....................................................................29
List of Examples
2-1. Hello World with AFP - hello.afp ........................................................................................................5
2-2. What time is it? - datetime.afp .............................................................................................................6
2-3. Access your data - allcust.afp...............................................................................................................6
2-4. Select your data - somecust.afp............................................................................................................7
3-1. Using events for Web applications - upload.afpa.code ......................................................................11
4-1. Default configuration - afp.default.config ..........................................................................................14
4-2. Activate debug mode - debug.afp.......................................................................................................18
4-3. Customized HTTP 500 error response ...............................................................................................20
5-1. Using the AFP 3.0 COM interface - VFP sample ..............................................................................24
6-1. Using the crypto plugin - crypto.afp ..................................................................................................34
6-2. The plugin loader................................................................................................................................35
vi
Welcome to the Active FoxPro Pages 3
[This topic is part of a beta release and is subject to change in future releases. Blank topics are included
as placeholders.]
Active FoxPro Pages provide a system for generating dynamic web pages with Microsoft Visual FoxPro,
XML and HTML.
Before using the Active FoxPro Pages you should spend the time to read the following important topic:
• What’s New in Active FoxPro Pages 3?
i
This Book’s Audience
This book gives you a comprehensive userguide to learn, understand and use AFPs to create effective
dynamic web applications.
We expect that most readers will have some familiarity with HTML or XML. Even if your experience
goes no farther than writing a few HTML pages, you’re probably in good shape. Although we provide an
introduction to HTML, XML and structured markup, this book may not suffice as your only tutorial
about HTML and XML. This depends, naturally, on your needs and experience.
Some prefaces of this book describe tools and applications. These are Microsoft Windows applications
only, cause Active FoxPro Pages only run on Microsoft Windows.
ii
Organisation of This Book
This book is divided into three parts:
Part I: Introduction - is an introduction to writing dynamic database-driven web sites with AFP
Part II: Reference - is a complete reference to every element and parameter entity in the AFP
Part III: Appendixes - discusses all other resources along with AFP
iii
Getting Examples from This Book
All of the examples in this manual are available online at the product’s web site. You can get the most
up-to-date version and information about the Active FoxPro Pages from the AFP web site:
http://www.afpages.com
iv
Request for Comments
Please help us improve future editions of this documentation by reporting any errors, inaccuracies, bugs,
misleading or confusing statements, and plain old typos that you find. The most recent version of this
document is available for download at http://www.afpages.com. Email your bug reports and comments to
us at [email protected].
v
I. Introduction
There are three reasons for becoming a
writer: the first is that you need the
money; the second that you have
something to say that you think the
world should know; the third is that you
can’t think what to do with the long
winter evenings.
Quentin Crisp
[This topic is part of a beta release and is subject to change in future releases. Blank topics are included
as placeholders.]
First we are show are the new features and improvements of version 3.0 inside the chapter What’s New
Chapter 1. What’s New?
[This topic is part of a beta release and is subject to change in future releases. Blank topics are included
as placeholders.]
This release is a complete new major release. And if I said major it means major. Nearly the complete
source code of the AFP was re-designed and re-structured to ensure more stability and performance for
your web application development.
With this new version we are entering a new concept of creating dynamic web sites with the AFP. Former
versions were file-oriented, by meaning that an URL request was responsed by a physical existing file.
However, with this release we’re introducing an application-centric, which means that the .AFP files are
boundable to a specific Web application. This application defines some global options. Additionally you
are able to use more meta data stored in XML files to control the behaviour of your .AFP documents.
Because of this new concept resulting in higher flexibility the current release is almost compliant and
compatible to former versions. We are talking about these aspects later in this UserGuide.
• Performance optimization: AFP 3 is significantly faster than AFP 2.4 and is able to manage several
million hits a day on a single computer. The entire design of AFP 3 has been optimized for
performance.
• No COM interface. The ISAPI extension communicates directly with the AFP engine. You don’t need
DCOMCNFG anymore. You can now stop AFP without shutting down the web server. There are none
of the conversion problems we had before with binary data.
• AFP 3 is a real multithreaded VFP application. This reduces memory and resource usage significantly
compared with AFP 2.4.
1
Chapter 1. What’s New?
• File upload
• Increased security: AFP 3 can run under the guest account. None of your files must reside in the
wwwroot directory and is therefore protected against direct access.
• The ControlCenter provides an overview over all running AFP threads including the currently
processed page and last execution time. You can load and unload individual threads at any time.
• The SessionID is now guaranteed to be unique. The declaration of session variables is much easier.
The entire session management has been reworked and now even offers session specific files, like
query results or generated reports. Those files are automatically deleted when a session times out.
• In each AFP page and AFP application you have a variety of events at your disposal letting you
execute code when an application is loaded, or before or after a page has been called.
• Error handling: You can specify an error handler for a single page and for the entire application
allowing you to response to error in your code. Since RETRY is supported, you can even automatically
repeat a failed record lock operation. Also, you can create your own dynamic errror pages.
• Each AFP application runs in its own datasession and has its own set of variables.
• A background job cleans up files.
• Plugins can be used to extend AFP in any imaginable way. Since the Plugin interface is documented,
anyone can create their own AFP plugins and share them with other developers.
• A new syntax allows you to execute code during the compilation of a page, letting you dynamically
change the page during compilation.
• During compilation you can include any file, including other AFP documents that also can include
more files. This makes it much easier to share common elements like the menu, header, etc. among
many AFP documents. Of course, if you change an include file, pages that use this file are
automatically recompiled.
• A compatibility layer allows the execution of AFP 2.4 applications. This layer also provides the FOX
object.
• The new object model is close to the ASP object model. This reduce the learning curve and allows you
to convert ASP samples much easier to AFP.
• Debugging has become much easier. In Debugmode AFP runs directly in the VFP 7 IDE on your web
server. This gives you the opportunity to use any of the debug commands in your AFP pages, like SET
STEP ON, ASSERT, DEBUGOUT, etc. Because the pages are called right from the web server, you
can test your AFP documents in the realistic context of your application. You merely call a page in the
browser and it appears in the debugger.
1.2. Requirements
System requirements for AFP version 3.0 are a little bit higher than with version 2.4:
• Windows NT/2000/XP
• ISAPI compliant web server (IIS 4 or higher, Apache 2.0.x or higher, WebWeaver, WebSite, etc.)
• Visual FoxPro 7.0 is highly recommended. Features like debugging and development of plugins
require VFP 7.
2
Chapter 1. What’s New?
New is the fact that Active FoxPro Pages 3.0 is shipped in two versions - Full version and Update version
- which is actually the same product but differs only at price and if you have a licensed version of AFP
2.x.
Also, a new matter is the host mangement of the Active FoxPro Pages. AFP supports three domains
native. A domain consists of a generic Top Level Domain (gTLD) like ’.de’ or ’.com’ and a user-defined
Second Level Domain (SLD) as ’active-foxpro-pages’ or ’afpages’. The result of gTLD and SLD is the
indicator for the AFP to observe.
Warning
The hostname of your Web server self is a potential bottle-neck to the concurrent
licenses. So avoid usage of domains for ’localhost’ or the short name of the
computer system, ie. ’afpserver’. These hostnames are encountered as SLDs and
in consequence restrict your amount of public Web sites.
Any sub-domains - like www.afpages.de or forum.afpages.de - are the same as afpages.de and therefore
ignored and unlimited. The domain limit is dynamically collected by the AFP. Once the limit is reached
all further requests to other AFP-enabled domains provoke a HTTP 500 error as response.
Any other domain will result in a HTTP 500 error. The following request would not work:
• http://www.prolib.de/
As you see, this is the fourth combination of gTLD and SLD and you get the expected error response.
Even though afpages.de and prolib.de reside on the same machine they are different domains.
3
Chapter 1. What’s New?
To increase the number of AFP-enabled domains / host names you will be able to buy additional host
licenses. Also, each legally independent Web site needs a separate host license.
If you host AFP sites for other companies or individuals, you MUST buy a host license for each
company or individual. Please contact [email protected] for details and pricing information.
1.4. Extensibility
Ever had this situation that you needed a special feature with the AFP? And this single one yesterday...
If you know what I’m talking about then you will enjoy the extensible plugins of the new Active FoxPro
Pages. With this plugin interface you are in a position to decide whether a specific feature of the AFP is
either needed or prohibited, to control the use of these plugins and even to develop your own add-ons.
4
Chapter 2. Getting Started
[This topic is part of a beta release and is subject to change in future releases. Blank topics are included
as placeholders.]
In this chapter we try to deliver you a light insight with some examples on creating and developing your
own Active-FoxPro-Pages.
All web components are stored in the "inetpub" directory on a Microsoft Internet Information Server.
This directory in turn contains a directory named wwwroot.
As soon as you address your Internet server, the default document is loaded. It is named "default.htm".
You may change that name at will. In the realm of Unix, the name "index.htm" is frequently used.
Another clue: you may also use "default.afp". "Addressing" means that you enter the domain name of
your machine in your Internet browser. If you don’t have your own domain name, the name assigned to
your machine will suffice within your network, or else "localhost", if you started the Internet browser on
your Internet server.
If all this gives no result, simply use the IP address of the Internet server. We will now deposit our first
AFP document in precisely that directory: \inetpub\wwwroot. To build your AFP document, you may use
any text editor you wish. In our example, we will simply use Notepad which is available on every
Windows machine.
<%
? "Hello World!"
%>
You can easily see that we are using two delimiters <% and %> to create an AFP code block. Everything
inside these delimiters is interpreted and parsed by the AFP engine. So, if you’re programming dynamic
web pages all your dynamic power goes into these code blocks.
AFP has no limits in mixing up different blocks with either AFPScript or HTML. It’s also possible to
’echo’ HTML code inside an scripting block. Later examples take care of this feature.
5
Chapter 2. Getting Started
Tip: Every example in this document is available on the CD shipped with your AFP package and on
the web site of the Active FoxPro Pages. The examples are at http://www.afpages.com/examples.afp.
<html>
<head>
<title>Dynamic Date and Time</title>
</head>
<body>
<%
? datetime()
%>
</body>
</html>
Now, call this page with http://localhost/datetime.afp in your favorite browser. This should display the
current time of the day.
In case that you made a mistake, a red screen might pop up - depends on your configuration. This
response is filled up with the complete documentation of anything that went wrong. Old AFP hands call
this the "Red Screen of Death" (an allusion to the infamous error screen appearing under Win NT, only in
a different color).
6
Chapter 2. Getting Started
<html>
<head>
<title>All customers of table CUSTOMER</title>
</head>
<body>
<h1 color="#0000FF">
<%?"All customers of table CUSTOMER"%>
</h1>
<hr>
<table border="1" width="95%">
<tr>
<td width="20%" bgcolor="#008000">cust_id</td>
<td width="40%" bgcolor="#008000">company</td>
<td width="40%" bgcolor="#008000">contact</td>
</tr>
<%
if not used("customer")
use JustPath(FILE.GetLocation()) + "\data\customer in 0
endif
select customer
scan
%>
<tr>
<td><%?customer.cust_id%></td>
<td><%?customer.company%></td>
<td><%?customer.contact%></td>
</tr>
<%endscan%>
</table>
</body>
</html>
For this purpose we extend the last example with a HTML textbox to specify the beginning letter of the
customers and modify our SCAN loop to take this into account of this specifacation.
7
Chapter 2. Getting Started
<html>
<head>
<title>Some customers of table CUSTOMER</title>
</head>
<body>
<h1 color="#0000FF">
<%?"Some customers of table CUSTOMER"%>
</h1>
<hr>
<form method="POST" action="somecust.afp">
<p>Please specify the starting letter:
<input type="text" name="searchkey" size="5">
<input type="submit" value="Query" name="B1">
</p>
</form>
select customer
lcsearchkey = upper(Request.Form("searchkey"))
if empty(lcsearchkey)
lcsearchkey=" "
endif
The first request of this page gives no results because no search string is specified. By submitting any
value for ’searchkey’ through the HTML form you receive the result table with the found records.
8
Chapter 2. Getting Started
To get the submitted data of the Web form to the Visual FoxPro code behind the scenes use the AFP
system function Request.Form(<cName>). In the example this function returns the value of the input
field named ’searchkey’. Attention, the string parameter of Request.Form() is case-sensitive.
9
Chapter 3. Creating Dynamic Web Sites
[This topic is part of a beta release and is subject to change in future releases. Blank topics are included
as placeholders.]
This chapter is intended to mix up the static presentation of HTML/XML in the former chapter with the
power and magic of the AFP. We’re going to create dynamic database-driven web applications.
• AppCall
• Error
• Init
• InitVariables
• Load
• LoadVariablesBefore
• PageAfter
• PageBefore
• PageCall
• PageCallAfter
• PageCallBefore
• Recompile
• SaveVariablesAfter
The availability of some events depends on the location there are used - free page or application. All are
very extensive explained in the reference section later in this UserGuide. So please refer to the
correspondent entry for further information.
While developing your Web applications these events are empty by default. So, it’s your choice to use or
leave them. Take a look at the compiled .PRG files below the %cache% to get an impression of this
mechanism.
What does this mean? - Imagine you create a Web application with multiple AFP documents to use
tables at every request. So, instead of placing your code inside your AFP document(s) to check and open
the tables if needed you write this code only once as an ’event’ to be executed. This saves a lot of time
while delevoping and executing your AFP doccuments.
10
Chapter 3. Creating Dynamic Web Sites
For better understanding, here is an example for the Init event which is ’fired’ at the very first start of
your Web application. It is part of the upload sample shipped with the AFP.
Procedure Event_Init
**************************************************************
* Open all tables
**************************************************************
USE AddBS(JustPath(FILE.GetLocation())) + "upload.dbf"
EndProc
Okay, let’s step through the structure of this code snipplet. First any event procedure is only allowed
inside .code files - either .afp.code or .afpa.code. Using upload.afpa.code means that the event is
part of a Web application (.afpa) called upload.
Next, the declaration of an event is wrapped with Procedure..EndProc. It’s absolutely mandatory to use
the EndProc to signalize the end of your event code. Because any source code written in your events is
compiled/copied ’as-is’ into the resulting page on first request. So, if the EndProc is missing you break
the structure of the whole page and activate an error.
Inside the event procedure you use simple VFP instructions and methods to do the job. AFPScript - code
blocks between <% and %> - is not allowed. Another restriction is to avoid the ’RETURN’ statement
cause this is interpreted as ’EXIT’ and interrupts the parsing process of the request which mostly
responds an empty document back to the users browser.
Events can be included multiple times into the resulting page. This depends on several factors - the
internal compiling process, the existence of the same event defined for free pages and applications,
whether the AFP document is free or application-bound and others. Also, there is no linear dependency
between the occurence of an event procedure in your .code file and the final location inside the
compiled page. If you are interested in how the compiling process actually works, enable Build Log and
examine the build-logs for details.
11
Chapter 4. Help
[This topic is part of a beta release and is subject to change in future releases. Blank topics are included
as placeholders.]
This chapter gives you a brief overview on several aspects like the installation of the AFP and debugging
your web applications.
4.1. Installation
The installation of the AFP is quite simple. Just run the afpsetup.exe and follow the instructions.
Okay, just a joke. Now, we are digging a little bit inside the setup routine and try to sneak a peek behind
the scenes. As already mentioned start the installation procedure by executing the afpsetup.exe. You
must have administrative rights on your machine to install but the setup checks this for you and in case if
not cancels the installation.
Additionally some more system requirements are checked before the setup actually starts. If your system
fulfills these prerequisites you are presented the license terms. Take a look at them.
Figure 4-1. By accepting the License Agreement you are able to install the AFP
By accepting the license agreement next is the ’main’ setup dialog. Here you are able to get the latest
breaking news about the AFP inside the ReadMe, you can determine your destination path for the AFP
and choose your prefered installation type - Recommended, Full or Advanced.
What does this mean? Hum, ’Recommended’ is the standard installation type which means that you are
about to install a pure AFP without any elder compatibility plugins but also without any flashy plugins
integrated with the setup - currently only plugin for Voodoo Web Controls available. A ’Full’ installation
is quite obviously the opposite and performs a heavy duty full installation with any integrated feature of
the setup routine - which means C24 and Voodoo plugins, currently. For the more sophisticated users
there is the ’Advanced’ installation type. Here, you have the possibilty to tweak and control any switch
inside the installation routine. The other side of the medal is that you get more dialogs to answer and
submit.
12
Chapter 4. Help
The next step is the actual file copying, installing and registering of the AFP into your operating system.
At the end of this step the AFP3 service will be installed and started and the shortcuts below the program
menu. At this point the AFP is running in your system.
But that’s not all. The setup tries to integrate the AFP file extension into your web server. If you are
running in advanced mode you are to choose this step on your own decision. Currently Apache is not
configured automagically but Microsoft Internet Information Services and VisNetic WebSite.
Still more dialogs? Puuuh, what a hard procedure, isn’t it? Okay, we’re through. The setup presents the
Finished dialog to you and you have the opportunity to choose more additional steps to be executed. It’s
always a good choice to visit the official website - maybe new version or erratas available?
Note: If you are running under Windows NT 4 you must reboot the system now to use the full
functionality of the AFP Control Center. Although the AFP3 service is up and running and the web
server would be ready to response any AFP request, you are unable to get the full throttle of the
AFP..
In case you did a Recommended or Full installation, the AFP 3.0 might already be configured with the
detected web server in your system. If installed Advanced you have seen a dialog on integrating the AFP
the easy way or not, right on your choice. Okay, the automagically procedure is currently realized for the
IIS, Apache 2.0.x, VisNetic WebSite and BRS WebWeaver.
Let’s look at the details. The metabase of IIS might be modified in that way, that the extension ’.AFP’ is
mapped to the correspondending AFP3.DLL with correct path. But, this is only done, if you don’t have
any existing extension mapping to the AFP.DLL of an prior version 2.4 or earlier. This is done at lowest
configuration level for IIS - configuration of the WWW Service - and not in any Website.
For using the AFP 3.0 in your (virtual) Websites you have to say the IIS, how to handle AFP documents.
Herefore right-click on the desired Website, choose Properties. A new dialog with several pages appears,
choose Home Directory (see Figure 4-4). Choose Configuration to see the existing Application
13
Chapter 4. Help
Mappings on the page Add Mappings (Figure 4-5). On this page you see how the several extensions are
mapped to their applications which handle them and respond back to the web server. Logically consistent
here is an entry for the extension .AFP mapped to the AFP3.DLL needed to explain IIS how deal with
AFP documents requested by a surfer on the chosen web site.
That’s all. Leave any dialogs by clicking on OK and re-start the AFP-enabled Website to activate the
changes just made. Re-starting might not necessary but we recommend it to do.
If you’re using Apache HTTP Server version 2.0.x the setup has copied a httpd.afp.conf into your ’conf’
directory. Please lookup any differences between your running configuration and the AFP-enabled one.
This one is based on the httpd.default.conf but without correct pathes to the AFP3.DLL. Yes, we know
that’s not fair and we try to solve this problem. Due to fact that the Apache has a complexer configuration
file with ’billions’ of directives and so on, we abstained from tweaking any existing configuration and
install only a standard conf file with enabled AFP configuration. Hope, this is in your mind.
This chapter deals with any option available inside the afp.config - the main configuration file for the
AFP 3.0. The structure of this file is just pure XML and also easy to understand, so you could tweak your
AFP by hand. We recommend to use the ControlCenter for the standard issues. Nevertheless modifying
the afp.config directly might useful for temporarly jobs.
For security reasons we distribute a ’default’ configuration file: afp.default.config. So, if you are
running into troubles with your modifications, just override the miss-formed XML file with the default
one and you are back on the road.
14
Chapter 4. Help
<afp>
<path root="" common="%root%" cache="%common%\cache" log="%root%\log"
session="%common%\Session" bin="%root%"/>
<server memory="1256000" valid-extensions="afp,htm,html,asp" threads="4"
isolated="YES" error=""/>
<session http-sessionid="YES" http-sessionname="afpcookie" afp-sessionid="YES"
afp-sessionname="afpcookie" file="%common%\Session.dbf"/>
<build compile-log="NO"/>
<debug afpengine="NO" cache-fxp="NO" show-error="NO"/>
<plugins>
</plugins>
<virtual name="/" secure="%common%\secure" securelevel="1">
</virtual>
</afp>
</config>
As you can see, the XML root for the AFP is <config> which contains an element called <afp>. Below
that one you get the attributes and values as configurable as with the ControlCenter. Every attribute
shown inside the several tags is mandatory and also case-sensitive - remember that please.
4.3.1. <path>
Okay, first there is the path tag which defines all the pathes available for your AFP instances, similar to
the Path page (Figure 5-4). Here you define the folders for %root%, %common%, %cache%, %log%,
%session% and %bin%. The values are regular paths on your system and should be absolute or as shown
relative to each other.
The %root% specifies where the AFP 3.0 engine running If this parameter is empty the same path as of
afp.config is used. The default value is empty.
If using the AFP in a clustering environment you define a common path for all associated Web servers to
find the system-wide files. The default value for common is %root% due to missing cluster.
Every first time a AFP document is requested it gets compiled by the Visual FoxPro Runtime. This
compilation results in an unique FXP file stored below the cache folder. Default value is %common%.
If enabling logging to external file rather than to the event log mechanism of Windows NT or higher set
the log attribute to the destination folder. The AFP uses that path to store any information araising during
execution. You might change the default path from %root%\log to the same path as used by your Web
server.
The session value specifies where the temporary session handles will be placed and removed by the AFP.
It’s definied below the %common% directory by default.
15
Chapter 4. Help
If using any additional applications specify the bin path and you are through. Logically it’s the same
directory as where the AFP engine lies within (%root%).
4.3.2. <server>
The next tag <server> handles the options for the AFP core engine. Here you are able to set the memory
usage, control valid extensions the AFP is allowed to parse and excute, information about the initial
threads to start and how they should be started. And finally what HTML file should be used to as
response if an error occurs. See also Figure 5-5.
The value for memory usage ist equal to the VFP function SYS(3050) to set the buffer memory size. This
makes it possible for you to optimize AFP/VFP performance by adjusting the amount of memory
AFP/VFP allocates for the foreground and background buffers. Additional to your Web server
configuration you can define allowed file extensions that should be parsed by the AFP as
comma-separated list. Next, you set the value of initial threads during re-start of the AFP engine. The
AFP Professional is limited to 10 threads maximum at the moment. The isolated attribute is a switch for
the AFP to run in different host environments. Yes, the AFP has at least two different running modes to
handle and execute your AFP documents - single threaded and multi threaded. If isolated is set to YES
your running in single-threaded modus. In this case the AFP3Host.exe represents each instance of the
AFP as single server managed via pool manager. This is the recommended modus while running with
C24 plugin for compatibility of older versions. Running in pure AFP 3.0 multi-threaded modus has more
performance with lesser system load, but also some restrictions in available functions to code your AFP
documents. The error attribute defines the user specific HTML file responsed if any error occurs during
execution. This is similar to the HTTP 500 error documents in your Web server. If this value is empty,
the default internal page of AFP is used.
4.3.3. <session>
The <session> attributes define if cookies and session are available in your AFP enviroment and set the
default names of these items - as shown on Figure 5-6.
The two ’http’ attributes handle the behaviour of HTTP cookies - if using at all and how to name them -
while the two ’afp’ parameters deal with the session environment. Due to compatibility reasons both
names are set to ’afpcookie’. For session is a limitation while running C24 to a maximum length of ten
characters and the value is created via the VFP system function SYS(2015) - Unique Procedure Name. In
deactivated C24 modus the name is normally ’sid’ and the length for the session id is approximate 44
characters.
The file attribute points to a DBF file. If the file does not exist it’s created automagically. This table
contains all information about running and active sessions, it’s the internal session management of the
16
Chapter 4. Help
AFP. The sessions itself are stored below the %session% value. May sound a little bit confusing but
actually it is not.
4.3.4. <build>
You can cause the AFP to create log files of the compiling process of your AFP documents inside the
<build>. Wow, what’s this good for? You may run into some troubles with your web applications, so with
the build logs you have another opportunity to check what was done inside the AFP and get a clue what’s
wrong with your document. So, this is a very detailed information what is done by the AFP. For
performance issues this option should be activated on your development machine only. See also Figure
5-7.
4.3.5. <debug>
Next, you see the <debug> attributes (Figure 5-8). Be careful with them, because you can stop your AFP
instances accidental with the wrong parameters here. So, these attributes are only interesting in your
development enviroment to get as much as available informations about your AFP documents. The
’afpengine’ reflects if debugging should interact with your VisualFoxPro IDE on your desktop. Please
take care of the amount of initial threads started, as this might pop up multiple VFP windows.
"Hey, I have no IDE of Visual FoxPro, what now?" - No problem, just set show-error to YES and you’ll
get the needed infos of your system enviroment, the source and the compiled source of your AFP
document as response to your browser if an error occurs. I guess you want this only in a secure area, like
an intranet. Caching the FXPs during development can be a nightmare for any programmer, so activate
this only on your productive system for better performance.
The default configuration of AFP 3.0 comes without any active <plugins>. So, it’s on you activate them.
We strongly recommend using only the plugins actually needed in your Web site. Because every
additional plugin slows down the AFP a little bit. Okay, we are talking about milliseconds but on
heavy-traffic Web sites this could be a matter. Herefore the ControlCenter offers a better user interface to
integrate the needed plugins (Figure 5-9).
Every plugin has its own <plugin> tag to set specific details like its location - represents the path where
the physical file lies; relative pathes like %root% can be used - and the associated engine (AFP) to handle
the plugin.
17
Chapter 4. Help
4.3.7. <virtual>
Now, it’s getting a bit complexer, and that for the configuration of this tag is not available inside the
ControlCenter. With the <virtual> tag and its attributes you can define your own virtual tree(s) used by
the AFP to get the requested AFP documents.
Imagine you request an URL like http://localhost/index.afp in your browser. The normal behaviour is
that there’s a physical file named index.afp below your public Web root (ie. IIS: C:\inetpub\wwwroot).
So, with the <virtual> directive you are able to define an additional directory tree for your Web root to
another, more secure path. This is comparable with the virtual directories of your Web server. The AFP
has its own virtual tree additional to the virtual tree of your Web server. Funny, ey? With this mechanism
the request first looks up the virtual tree of the Web server and then afterwards the virtual tree of the AFP.
More to come...
Here is a short example how to activate the debugging mode in your .AFP file:
<%
ASSERT .F. MESSAGE "Debug me, please..."
? "Hello World!"
%>
This opens the debug window on the web server and you are able to inspect the malicious code.
Note: It opens the debug window on the web server. So, don’t activate the debug mode by setting
afpengine=YES on your productive system public achievable on the internet. This ain’t funny...
18
Chapter 4. Help
The AFP provides several possibilities to track down occuring errors. This depends on the one hand on
the settings in afp.config and on the other hand where the error actually raised.
Let’s take a look at the possible configuration settings for error handling. The AFP reports its information
and error messages to the Windows Event Log regular. To view them, launch the Event Viewer and
choose the Application Log. This gives you a good flexibility and enough opportunities to read those
messages via the standard tools of your operating system. Even from and to remote machines.
If the Web server is part of a cluster of several machines, now, all AFP related messages from these single
machines can be collected and controlled on a separate computer. That’s a very nice feature, isn’t it?
Due to security or firewal issues using the eventlog mechanism might be impossible. But don’t hestiate
the AFP has a second way to report any important events or errors. Herefore, take a closer look at the
’logfile’ attribute of the debug tag of your configuration. With this option you specify a plain ASCII log
file where the AFP has to report additional to the EventLog (see Figure 4-8). This is quite useful if you
either have restricted access to the machine (ie. FTP only) or in need to send the file to your mail account
at the office or just want to check status via your mobile. So, it’s on you how to use and like this setting.
See Section 4.3.5 and Section 5.4.2.5 for more details and explainations. Logging to file is turned off by
default.
The two figures Figure 4-7 and Figure 4-8 present the same information in different formats. Choose
your preferred one.
19
Chapter 4. Help
In need of a handier way to inform your visitors about an occured error other than that plain HTTP 500
error messages? Okay, place a customized HTML file into the application path of the AFP. Depending on
the set value in <server error=""> the AFP responses a customized HTTP 500. If the error attribute is
empty the AFP looks for a default file named HTTPError.html. You are absolutely free to choose
another file name.
But that’s not all - guess what? Yes, even in this HTML file it’s possible to use dynamic information. The
only difference is that it must be pure VFP code - no AFPScript, no delimiters like <% or %> - and
embedded inside the standard textmerge delimiters << and >> of Visual FoxPro. Knowing this little
detail you are to provide etxra information collected at the moment the error occured and present them in
your browser.
<html>
<head>
<title>Sorry, work-in-progress!</title>
</head>
<body>
<h2>Dear visitor,</h2>
due to some re-configuration on our billing system, it’s not possible to send any orders
at the moment. We are working on that and the system should be running perfectly in about
<<22 - HOUR(DATETIME())>> hours this day.
<p>
Please be patient, sincerely.
</body>
</html>
The error attribute is recommended to be used to inform the visitor if there’s something wrong or broken
with the Web server or service. Look at Section 4.3.2 and Section 5.4.2.2 for more.
The presented options for error reporting might be quite useful for normal operation mode, but what
about errors at design time or during development? - Okay, okay. Also in this case gives the AFP a nice
feature at your hands - ’The Red Screen of Death’. Sounds funny, ey? In any way this internal is enabled
or disabled by the attribute show-errors inside the debug options. Please refer to Section 4.3.5 and
Section 5.4.2.5 if this sounds absolutely new.
For illustration look at Figure 4-9 below. It’s strongly recommended to deactivate that setting caue it
exposes many details about your system and its configuration - paths and environment variables
included.
20
Chapter 4. Help
21
Chapter 5. AFP Applications
[This topic is part of a beta release and is subject to change in future releases. Blank topics are included
as placeholders.]
The Active FoxPro Pages are very modularized and offer many configuration parameters to enhance the
developing process of Web applications and to optimize the response times to a minimum on your public
internet Web server. To achieve this flexibility the AFP consists of several applications. This chapter
gives a brief overview on them.
Generally, the AFP consists of four components which interact and communicate with each other.
• ISAPI interface
• AFP Engine
• AFP Server
• Configuration
The ISAPI extension has an optional configuration file AFP3.INI with only one option to specify is the
’BusyTimeout’ for the ISAPI extension which specifies the number of seconds AFP3.DLL waits for the
response of the AFP engine before a time-out message is generated. If this item is omitted or if
AFP3.INI isn’t present the default is 30 seconds.
22
Chapter 5. AFP Applications
used is specified by the attributes for isolated and afpengine. For detailed information read the section
Section 4.3.
Normally the AFP runs in multi-threaded environment - AFP3Engine.DLL (MTDLL) - and offers the
most performance at least system load. The restrictions of VFP in MTDLL mode prohibit usage of some
native functions. See Appendix A for prohibited and problematic functions.
In case of necessity of these functions, either in your AFP documents or in your plugins, change the
environment of the AFP engine to single-threaded but multi-use - AFP3Host.exe (EXE) - and use them
as usual. Okay, that’s a little tribute to lesser performance and higher system load but remember, we are
talking about milliseconds however.
Finally the most interesting mode for you as AFP developer might be the new debug mode. This requires
a complete development environment of Microsoft Visual FoxPro 7 or higher. To enable AFP to debug
mode set afpengine to ’YES’ in your afp.config (see Section 4.3.5) or simply check ’Debug engine’
on the Debug page in AFP 3.0 ControlCenter (see Section 5.4.2.5).
The AFP engine can’t act as a standalone application, it needs to be started by an AFP server.
For developing Web applications a better handling of the AFP server other than stopping and starting the
service via its control panel is necessary. Using the standalone AFP3.EXE gives the developer a desktop
application to start/stop the AFP on demand.
Tip: Create a shortcut to the AFP3.EXE in the Quick Launch section on the Taskbar. Saves you
clicks and time during development.
23
Chapter 5. AFP Applications
Last interface to the AFP server component is COM. With the shipped type library OLE automation with
the AFP 3.0 works like a charm. Here is short sample on how to do this.
Example 5-1. Using the AFP 3.0 COM interface - VFP sample
oAFP = CREATEOBJECT("AFP3.Server")
oAFP.StartUp("C:\Program Files\AFP3\afp.config")
READ EVENTS
oAFP.ShutDown()
5.4.1. Status
The Status dialog gives information about the running AFP instances. This includes last processed AFP
document, duration time to process. Additionally creation of new instances - either normal engine or
debug engine - and also termination is possible wihtout the need to re-start the whole AFP.
24
Chapter 5. AFP Applications
5.4.2. Config
5.4.2.1. Path
First I talk a little bit about the AFP configuration. The afp.config is just a small XML document
which is read at every start of the AFP - either starting the service below the computer management or
executing the AFP3.exe. So if you’re changing any parameters remember to re-start the AFP. I think this
behaviour is more useful than the standard of windows applications which is to react instantly to any
configuration changes because you make your modifications without interrupting the running instance
and may eg. schedule the re-start of the AFP in the future.
Alright, let’s look at the config dialog of the ControlCenter. There are several tabs which automagically
represent the different sections inside the XML configuration file. We are getting through every single
one of them.
The Path page defines any path declarations used inside the AFP. The Root Directory specifies where
the AFP3.exe running equal to selected destination folder specified at installation. If this parameter is
empty the path of the afp.config is used as root of the AFP. Default this value is empty.
For clustering purposes the Common Files directive specifies the common path for several web servers
running AFP where to find the system-wide files. This should also include a common cache and session
path as defined as default. The default value for Common Files is %root% due to a single machine.
Every first time a AFP document is requested it gets compiled by the Visual FoxPro Runtime. This
compilation results in an unique FXP file stored below the Cache path. Default the Cache Directory is
below %common%.
If enabling logging to external file rather than to the event log mechanism of Windows NT or higher set
the Log Files directive to the destination folder. The AFP uses that path to store any information araising
during execution. Although Windows gives you the opportunity to access the event log remotely it might
be more secure or easier to get your log files via FTP. You might change the default path from
%root%\log to the same path as used by your Web server or your Web site.
The Session directive specifies where the temporary session handles will be placed and removed by the
AFP. It’s definied below the %common% directory by default.
If using any additional Program Files specify this directive and you’re through. Logically it’s the same
directory as where the AFP engine lies within (%root%).
25
Chapter 5. AFP Applications
5.4.2.2. Server
Okay, let’s talk a little bit about the initial Server parameters used at every re-start of the AFP. On this
page the allocated Memory (in bytes) for the AFP engine is specified. Depending on the hardware
specifications of your system can tweak the performance additionally.
Also it’s very useful to set an initial value about useable Threads for the AFP engine. The default value is
four but actually there are no limitians other than your system abilities (amount of RAM).
The declaration of Valid Extensions is absolutely necessary even mandatory for parsing any AFP
document anyway. Although the primary controlling instance for the extensions lies inside the Web
server configuration the AFP is able to restrict the allowed extensions in second level. So, if you eg. want
to AFP-enable .WML documents it’s definitly necessary that ’wml’ is a Valid Extension for the AFP to
deal with. Otherwise you’ll get a simple HTTP 500 error that indicates that the server can’t process the
requested page due to a server error.
Note: The Valid Extensions directive declares only the allowed extensions for the AFP engine to deal
with but actually does NO extension mapping of your Web server. The extensions are only
double-checked for AFP-based Parsing.
While running the AFP engine with activated C24 plugin it’s better run activate Isolated AFP Thread. In
fact the AFP runs as multi instances of a single server named AFP3Host.exe instead of a mutlithreaded
DLL AFP3Engine.dll. The difference between these two operating modes lies in the architecture of
Visual FoxPro itself cause a multithreaded enviroment has some limitations about the useable comands
and functions. For example there’s no way to use the CD command for changing directories.
Create and show your own error messages with the Error HTML file directive while an error might
occur. As very handy feature this can even be an AFP document which is processed before responded to
the users browser. This might be better than sending an ordinary HTTP 500 or even worse the Red
Screen of Death. Refer to the chapter Error Handling for further information.
5.4.2.3. Session
Next we perform the options to interact with the users activities on the Web site. Herefore we use either
cookies or sessions. What’s the difference between them? Cookies a little ASCII text snipplets send forth
and back between user’s browser and the Web site on every request. With this mechanism it’s easy to
keep track of or store info about a single user during their visits and later for recognition. Due to the facts
that cookies were mal-used in the past there is another mechanism to trace down users activities:
sessions.
26
Chapter 5. AFP Applications
Sessions are the successor of the ’AFP cookies’of versions before AFP 3.0. With sessions management
you don’t have to store any information on the client computer because the session is stored on the Web
server below the %session% path and part of every responded web request. How does this work? It’s
easy cause the session id is either integrated into the URL or as hidden value inside HTML forms. In
consequence every hyperlink (nearly every because external links don’t need them) or HTML form
presented to the user contains its own session. And you are able to trace and keep track of your visitors.
Cookies are client-sided small text informations while sessions are server-sided. Take care of the fact that
cookies can be deactivated by the requestor.
Okay, back on the configuration page configuration for both mechanism is provided to you. You define if
you even want HTTP-Session-ID (Cookies) and how that small text file should be named - Cookie name
- on the visitor’s machine.
Alternativly or additionally you define to use AFP-Session-IDs (Sessions) and their appropiate
identification string in your URL. Former versions of AFP used the string ’afpcookie’. As with version
3.0 the default is ’sid’ - short form of ’session id’. The Session File acts as management table to keep an
overview over all the different sessions and to perform cleanups if the single sessions overcome their
timeout limit. Normally it resides below the %common% path while the session itself is below the
%session% path defined on the Path page. See Figure 5-6 for details.
Due to the fact that every first request of a modified AFP document the AFP engine builds a new
compiled version of this document to increase performance you can activate logging for this procedure
(Figure 5-7). Mostly this is only reasonable on your development system but not on your live server on
the Web.
5.4.2.5. Debug
Now, we speak a little bit about error tracing and tracking with the AFP 3.0. This section is completely
new since this version and very amazing to handle. Actually it’s funny and absolutely easy to debug AFP
documents. What do we need? Hum, in fact only an AFP Debug Engine and an (optional) full version of
27
Chapter 5. AFP Applications
Visual FoxPro 7. Wow, do I need the Visual FoxPro IDE - no you don’t but it’s easier if you own one.
Please refer to section Debug Mode for details.
Also on the Debug page you define if the generated compiled AFP documents - FXP files - should be
cached. For performance reason it’s better to enable caching on your live system. In consequence the
documents reside in the memory of your Web server and respond quicker. On a development machine
preference lies on disabled caching cause then you are able to cleanp up the %cache% directory without
stopping the AFP engine.
Show error message in browser - this (de-)activates the Red Screen of Death if any parsing or
systematic error occurs inside your AFP documents. Take care of this option! For security reasons
activate this only on your development enviroment but not your live system. The generated error message
contains a lot information about your system and might open wide doors to crackers to knock down your
Web server. Details are discussed in the section about Error Handling.
5.4.2.6. Plugin
An absolutely new highlight of the AFP version 3.0 is the ability to increase and decrease its
functionality and power dynamicly. With Plugin management you are able to set up your own AFP
enviroment which best fits your needs. And as the state-of-the-art you are even able to write your own
plugins to enhance the AFP. To manage the plugins you specify them on the Plugin page, re-start the
AFP engine and enjoy them.
Currently the AFP ships with three and a ’half’ plugins - C24 Fox and C24 Cookie, Voodoo Web
Controls and DirectCall. It’s recommended to specify the relative path to the plugins with the Path
variables. Default, the plugins reside below the %root% path but absolute paths are possible, too.
Detailed information about plugins and their development is described in the Developer’s Guide to
Active FoxPro Pages 3.0.
5.4.2.7. License
Although the AFP is fully functional in demo mode, it’s always a nice move to purchase a license.
Entering your license is quite easy. Specify the Name and Serial Number, send the resulting Hardware
Key to your distributor to obtain an Activation Key.
28
Chapter 5. AFP Applications
A licensed version of the AFP lacks the appearence of the demo table at the top of every processed AFP
document and the nag screen every 15 minutes.
29
Chapter 6. Plugins
[This topic is part of a beta release and is subject to change in future releases. Blank topics are included
as placeholders.]
In this chapter we’re talking about the plugin interface of the Active FoxPro Pages. Plugins give you a
flexible way to enhance the power of the AFP to your belongings. As you already might have seen, the
standard edition of the AFP comes with some optional plugins like the compatibility plugins for the
previous AFP version 2.4.
Here is an alphabetical overview of the properties and methods the C24 plugin takes care of and some
suggestions which properties and methods should be used in version 3.0 instead. For your explanation
these tables do NOT represent the functionality of the C24 plugin but a conversion help and reference for
you to get a starting point for the new AFP 3.0 syntax without the need of C24.
30
Chapter 6. Plugins
FOX.cIni * obsolete *
Due to the new communication structures between
AFP 3.0 and the Web server, there is no need for
the .INI files used by version 2.4 anymore
FOX.cIniFile * obsolete *
Due to the new communication structures between
AFP 3.0 and the Web server, there is no need for
the .INI files used by version 2.4 anymore
FOX.cLanguage REQUEST.ServerVariables(
"HTTP_ACCEPT_LANGAGE" )
FOX.cLogFile * obsolete *
Use the capabilities of the Event Viewer of
Microsoft Windows NT and higher, the separate
error-log file and the native VFP Debugger for this
property.
FOX.cParameter REQUEST.QueryString()
FOX.cPath FILE.cLocation
FOX.cPathInfo FILE.cVirtualLocation
31
Chapter 6. Plugins
FOX.cTimeStamp * obsolete *
Use the log files of the Web server instead. If
needed, implementation is very easy using
FILETOSTR() with a customized string in
combination with some server variables and time
stamp.
FOX.cVersion SERVER.Version()
FOX.lAFP2ASP
FOX.lAutoCookie afp.config: http-sessionid="YES" | "NO"
FOX.lAutoLocalize
FOX.lCloseAll * obsolete *
FOX.lConvertAlways * obsolete *
Use SERVER.HTMLEncode() instead
FOX.lWorkAsFXP * obsolete *
32
Chapter 6. Plugins
FOX.SetHttpCookie() RESPONSE.AddHeader()
FOX.Write() Obsolete and easy to implement yourself
33
Chapter 6. Plugins
add a new <plugin>-Tag to your afp.config and re-start the AFP engines.
Now, you have a crypto object available to your AFP documents. Currently there are three methods to
work with:
• Encrypt()
• Decrypt()
• Checksum()
And here’s a basic example on how to use the crypto plugin and its syntax.
<%
lcString = "This sentence is top secret."
? "Original string: ’" + lcString + "’"
? "<p>Let’s look at the results:"
? "<br>CRYPTO.Encrypt(): " + CRYPTO.Encrypt(lcString)
? "<br>CRYPTO.Decrypt(): " + CRYPTO.Decrypt(CRYPTO.Encrypt(lcString))
%>
What is a plugin?.
A plugin for the AFP is just a normal Microsoft Visual FoxPro 7 compiled application - either .APP,
.EXE or .FXP. To integrate your VFP application as plugin to the AFP you have to add a new <plugin>
tag in the afp.config which refers to your program. After successfully reloading the AFP engine your
.AFP documents can use your plugin. That’s all, almost.
An AFP plugin has to fullfil several requirements before it loads to the AFP engine anyway and here they
are.
34
Chapter 6. Plugins
6.4.1. Requirements
Before you can use your own plugins, they have to match a specific interface given by the plugin
management of the AFP. In this section we explore this interface and you will see that is very easy to
write your own add-ons.
If the AFP starts a plugin one parameter by reference is passed to add this object to its plugin
management.
6.4.1.1. cID
A short identifier string to represent or list the loaded plugin on the information page of AFP.
6.4.1.2. Load-Method
Obviously the initializing method to specify any defaults or pre-requisities the plugins needs - like the
global variable wanted in any AFP document.
6.4.1.3. Unload-Method
While an AFP engine quits, the plugin management calls the Unload method of every loaded plugin to
release itself gracefully. So, this method is to clean up the plugin environment and to release any objects
to avoid dangling references.
To use an VFP application as AFP plugin you have to load it through the plugin management. Here is
sample code on how this should be done (taken from the voodoo plugin).
*======================================================================
* The Loader creates an instance of the CPlugIn object and passes it
* back to the caller.
*======================================================================
LParameter roPlugIn
35
Chapter 6. Plugins
roPlugIn = CreateObject("CPlugIn_Voodoo")
*======================================================================
* CPlugIn_Voodoo
*
* Implements the REQUEST and WebPage classes as needed by Voodoo.
*======================================================================
Define Class CPlugIn_Voodoo as CPlugin
cID = "VOODOO"
*======================================================================
* Make the classes available to AFP. All Subclasses must be in the main
* procedure file.
* Otherwise, VFP is not able to find them.
*======================================================================
Procedure Load
Local lcVoodoo, lcPath
If not Upper(JustPath(This.cFullFileName)) $ Upper(Set("Path"))
lcPath = Set("Path")
If not Empty(m.lcPath)
lcPath = m.lcPath + ","
EndIf
lcPath = m.lcPath + JustPath(This.cFullFileName)
Set Path To &lcPath
EndIf
Set Procedure To ("Voodoo") Additive
Set Procedure To (This.cFullFileName) Additive
EndProc
*======================================================================
* Get rid of the procedure files
*======================================================================
Procedure Unload
Release Procedure ("Voodoo")
Release Procedure (This.cFullFileName)
EndProc
EndDefine
First the plugin loader should be the main program of your project that handles the parameter passed
from the AFP management. This parameter is passed by reference and returns actually the object.
Any plugin should inherit from the CPlugin class of the AFP. It’s a commendation for your plugins but
not mandatory. And why not using the offered plugin base? You have the choice.
36
Chapter 6. Plugins
Now, the source code fullfils the plugin requirements - cID property and load/unload methods. It should
be clear what’s going on. The Voodoo plugin checks if the needed procedure file voodoo.fxp for the
Voodoo Web Controls is in path of the plugin at the begin and releases the additive procedure at the end.
37
II. Reference
Reality is for people who lack
imagination.
anonymous
Chapter 7. Objects
[This topic is part of a beta release and is subject to change in future releases. Blank topics are included
as placeholders.]
App-Object
Name
App-Object — represents a separate application in the AFP enviroment.
Synopsis
App
Notes
The APP object is only available when a page is part of an AFP application. Applications have a private
datasession. Files open in onw application are not visible to other applications.
Properties
cFile
cID
See also
39
Chapter 7. Objects
File-Object
Name
File-Object — represents the curremt executed .AFP document.
Synopsis
File
Notes
The FILE object represents the .AFP document that is executed. In AFP, a file object manages the
physical location and the location within the virtual directory tree of a web site.
Properties
cLocation
cVirtualLocation
Methods
AddExtension()
Clone()
GetCacheName()
GetLocation()
Relative()
Reset()
ResolveRelative()
See also
40
Chapter 7. Objects
Path-Object
Name
Path-Object — contains all informations about path configuration.
Synopsis
Path
Notes
Properties
cCache
cCommon
cLog
cRoot
cSession
Methods
MakePath()
See also
41
Chapter 7. Objects
Request-Object
Name
Request-Object — holds parameters about the request sent by th web server and browser.
Synopsis
Request
Notes
The request object contains all the incoming data from a web request. These informations are sent from
the users browser, the web server handling the request and the requested url in the user’s browser.
Methods
Cookies()
Form()
MultiPart()
QueryString()
Reset()
ServerVariables()
See also
Response-Object
Name
Response-Object — handles all content sent back to the browser.
42
Chapter 7. Objects
Synopsis
Response
Notes
The Response object collects all information to send them back to the users browsers. The object has two
different kinds of data - HTTP header and content.
Properties
Methods
AddHeader()
BinaryWrite()
Body()
Clear()
Cookies()
Document()
Header()
HTTPCookie()
Redirect()
Reset()
Write()
See also
Server-Object
Name
Server-Object —
43
Chapter 7. Objects
Synopsis
Server
Notes
Methods
DoCmd()
Execute()
HTMLDecode()
HTMLEncode()
MapPath()
Transfer()
URLDecode()
URLEncode()
See also
Session-Object
Name
Session-Object — manages the session id.
Synopsis
Session
44
Chapter 7. Objects
Notes
However, it does not manage variables or persistent contents! In AFP 3.0 a session is created, when you
call the SESSION.SessionID() function. If you don’t call it, no session is created. Sessions are managed
in a table SESSION.DBF which sits in the common directory.
Each time you renew a session or a request comes in that contains session information, a time stamp is
updated. Session information can be carried in two forms: Either as a HTTP cookie or as a QueryString
parameter. The name of both are configurable in the afp.config file. The default is "sid" for session ID,
but in the sample config file it has been changed to "afpcookie" for backward compatibility reasons.
The C24_Cookie plugIn replaces this session object. CreateSessionID() returns the old SYS(2015)
setting. Also, the ?!_XXXXXXXXX Syntax is regonized as a session ID.
The session object works closely with the ControlServer (AFPCS.EXE). This server is running in the
background and removing old session data. This ensures that a request is not slowed down due to
garbage collections.
Methods
Abandon()
CreateSessionID()
GetSessionCookie()
GetSessionData()
GetSessionFileName()
IsNew()
NewSession()
ReNew()
SessionID()
SetSessionData()
Timeout()
URL()
See also
45
Chapter 8. Properties
[This topic is part of a beta release and is subject to change in future releases. Blank topics are included
as placeholders.]
cCache-Property
Name
cCache-Property —
Synopsis
Path.cCache [ = cDirectory]
Attribute values
Notes
The cache directory contains all the compiled AFP documents. You can safely delete all files in there.
The cache can be a local directory. The default is %common%/cache.
Example
See also
cCommon-Property
Name
cCommon-Property —
46
Chapter 8. Properties
Synopsis
Path.cCommon [ = cDirectory]
Attribute values
Notes
Common directory. This directory must be accessible from all AFP instances. Default is %root%.
Example
See also
cData-Property
Name
cData-Property —
Synopsis
Request.cData
Attribute values
Notes
47
Chapter 8. Properties
Example
See also
cFile-Property
Name
cFile-Property — name of the application file in the local cache.
Synopsis
App.cFile
Attribute values
Notes
Example
See also
48
Chapter 8. Properties
cID-Property
Name
cID-Property — ID of the application.
Synopsis
App.cID
Attribute values
Notes
This ID is used when variables are stored. Two applications with the same ID change the same set of
variables, but not the same set of files.
Example
See also
cLocation-Property
Name
cLocation-Property — Physical file as specified by the web server in the PATH_TRANSLATED
server variable.
Synopsis
File.cLocation
49
Chapter 8. Properties
Attribute values
Notes
Example
See also
cLog-Property
Name
cLog-Property —
Synopsis
Path.cLog [ = cDirectory]
Attribute values
Notes
Log directory. All log files produced by AFP are saved here. Default is %root%\log
Example
50
Chapter 8. Properties
See also
ContentType-Property
Name
ContentType-Property —
Synopsis
Response.ContentType [ = cContentType]
Attribute values
Notes
Example
Response.ContentType = "application/pdf"
See also
AddHeader-Method
51
Chapter 8. Properties
Cookie-Property
Name
Cookie-Property —
Synopsis
Response.Cookie
Attribute values
Notes
Example
See also
AddCookie-Method | GetCookieHeader-Method
cRoot-Property
Name
cRoot-Property —
Synopsis
Path.cRoot [ = cDirectory]
52
Chapter 8. Properties
Attribute values
Notes
Example
See also
cSession-Property
Name
cSession-Property —
Synopsis
Path.cSession
Attribute values
Notes
Session directory. All session information are stored here. Therefore this directory must be accessible by
all AFP instances. IMPORTANT: All files in this directory are deleted unless they belong to a valid
session. The default is %common%/session.
53
Chapter 8. Properties
Example
See also
cVirtualLocation-Property
Name
cVirtualLocation-Property — Location of the file in the WebServers hierarchy.
Synopsis
File.cVirtualLocation
Attribute values
Notes
Example
See also
54
Chapter 8. Properties
Expires-Property
Name
Expires-Property — Expiration date of the responsed page.
Synopsis
Response.Expires [ = Date]
Attribute values
Date
Notes
Example
<%
Response.Expires = DATE() + 1
%>
</para>
</refsect1>
<refsect1><title>See also</title>
<para>
</para>
</refsect1>
</refentry>
<refentry id="response.status">
<refnamediv>
<refname>Status-Property</refname>
<refpurpose>sets the HTTP response status.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<cmdsynopsis>
<command>Response.Status</command>
<arg choice="opt">
<option>= cHTTPStatusCode</option>
</arg>
</cmdsynopsis>
55
Chapter 8. Properties
</refsynopsisdiv>
<refsect1><title>Attribute values</title>
<para>
</para>
</refsect1>
<refsect1><title>Notes</title>
<para>
</para>
</refsect1>
<refsect1><title>Example</title>
<para>
Invoke a redirection to another URL:
<screen><![CDATA[
Response.Status = "301"
Response.AddHeader("URI", "http://www.active-foxpro-pages.com")
See also
AddHeader-Method
56
Chapter 9. Methods
[This topic is part of a beta release and is subject to change in future releases. Blank topics are included
as placeholders.]
Abandon-Method
Name
Abandon-Method — terminates the current session.
Synopsis
Session.Abandon( )
Return values
Parameters
Notes
The session cannot be recovered. You can call this method to implement a logoff feature to ensure that
sensitive data is not available to the next user on a computer.
Example
The following document could be used to log out the current user. Once the session has been abandoned,
the browser is redirected to the login page letting the next user log onto the system. When you design
applications that might be used from public computers, you should always provide an explicit logout
option. Otherwise the next visitor might gain access to private data of a previous user.
LogOut.AFP
<%
SESSION.Abandon()
RESPONSE.Redirect("Login.afp")
%>
57
Chapter 9. Methods
See also
AddExtension-Method
Name
AddExtension-Method — returns a new file object that has been extended by the string in
cExtension.
Synopsis
Response.AddExtension( cExtension )
Return values
Object
Parameters
cExtension
File extension to add to the current file.
Notes
Tjoa...
Example
For example, file.AddExtension(".config") returns a file object that represents the configuration file.
<%
oFile = FILE.AddExtension(".config")
%>
58
Chapter 9. Methods
See also
AddCookie-Method
Name
AddCookie-Method — adds a user-defined cookie information to the response.
Synopsis
Return values
Logical
Parameters
cName
Name of the cookie to send back to the client
cValue
Corresponding value for the specified cookie
cPath
Corresponding path for the specified cookie
uDate
Expiration date of the cookie. Allowed value type are string and date.
59
Chapter 9. Methods
Notes
The AddCookie-Method gives the opportunity to send your own cookies with their properties back to the
clients browser.
Example
<%
Response.AddCookie("AFP", "Active FoxPro Pages", "/", DATE() + 1)
%>
See also
AddHeader-Method
Name
AddHeader-Method — adds user-defined information to the HTTP header.
Synopsis
Return values
Logical
Parameters
cKey
Keyword to add to the HTTP Header.
60
Chapter 9. Methods
cValue
Corresponding value for the specified keyword
Notes
The AddHeader-Method gives the opportunity to add own keywords and values to the HTTP Header.
This only possible before any response is sent back to the browser.
Example
<%
*// write additional HTTP-Header.
*// X-Powered-By: AFP/<version>
Response.AddHeader("X-Powered-By", "AFP/" + SERVER.Version())
See also
BinaryWrite-Method
Name
BinaryWrite-Method — returns any binary file
61
Chapter 9. Methods
Synopsis
Response.( cData )
Return values
Character
Parameters
cData
Any data content to send back to the client’s browser.
Notes
The method adds the binary content to the response buffer and does not handle any content type
information. So if you want to respond, ie. a PDF file you have to set the correct content type additive.
Example
<%
lcPDFFile = AddBS(JustPath(FILE.GetLocation())) + "UserGuide.pdf"
Response.ContentType = "application/pdf"
Response.BinaryWrite(lcPDFFile)
%>
See also
ContentType-Property
62
Chapter 9. Methods
Body-Method
Name
Body-Method — returns the HTML content from the response buffer
Synopsis
Response.Body( )
Return values
Character
Parameters
Notes
Example
<html><body>
Let’s look at the resulting HTML generated by the AFP:
<p>
<%? Response.Body()%>
</body></html>
See also
63
Chapter 9. Methods
Call-Method
Name
Call-Method — calls a new AFP document to be executed.
Synopsis
Response.Call( cLocation )
Return values
Logical
Parameters
cLocation
Notes
With this method you are able to interrupt and empty your response buffer and continue with a new AFP
document to send back to the browser. The current AFP page is no longer executed. This includes any
information send either to the HTTP header or cookies.
Example
For example in an online calendar you are able to send different responses due to the current year. This is
quite useful, cause mostly the office is closed around new year.
<%
IF YEAR() = 2003
Response.Call("happynewyear.afp")
ENDIF
64
Chapter 9. Methods
See also
Redirect-Method | Transfer-Method
Clear-Method
Name
Clear-Method — empties the response buffer.
Synopsis
Response.Clear( )
Return values
Logical
Parameters
Notes
Sets the response buffer back to an empty string. HTTP header and cookies are not affected.
Example
<html><body>
<h2>Congratulations, You won!</h2>
<%
IF lcName = "wOOdy"
Response.Clear()
%>
<html><body>
<h2>Sorry, you’re a team member...</h2>
<%
ENDIF
65
Chapter 9. Methods
%>
<p>Best wishes, your <i>AFP Team</i>
</body></html>
See also
Reset-Method
Clone-Method
Name
Clone-Method — returns an exact copy of the current file object.
Synopsis
Response.Document( )
Return values
Object
Parameters
Notes
Example
<%
loFile = FILE.Clone()
%>
66
Chapter 9. Methods
See also
AddExtension-Method
CookieDate-Method
Name
CookieDate-Method — converts specified date to a cookie conform string.
Synopsis
Response.CookieDate( dDate )
Return values
Character
Parameters
Notes
Formerly FOX.CookieDate()
Example
<%
lcCookieDate = Response.CookieDate(DATE() + 1)
%>
67
Chapter 9. Methods
See also
Cookies-Method
Name
Cookies-Method — returns a HTTP Cookie sent by the client.
Synopsis
Request.Cookies( )
Return values
Character
Parameters
Notes
Formerly FOX.GetHTTPCookie()
Example
<%
lcCookie = Request.Cookies()
%>
68
Chapter 9. Methods
See also
CreateSessionID-Method
Name
CreateSessionID-Method — returns a new session ID, but does not replace the current one.
Synopsis
Session.CreateSessionID( )
Return values
Character
Parameters
Notes
You can use this function to create a unqique ID for other purposes, as well. With the C24_Plugin this
method is identical to SYS(2015).
Example
See also
69
Chapter 9. Methods
DoCmd-Method
Name
DoCmd-Method — executes VFP code and returns the error code
Synopsis
Server.DoCmd( )
Description
Document-Method
Name
Document-Method —
Synopsis
Response.Document( )
Return values
Parameters
Notes
70
Chapter 9. Methods
Example
See also
Execute-Method
Name
Execute-Method — executes AFP code on the fly. The result is added to the response buffer.
Synopsis
Server.Execute( cAFPCode )
Notes
Joh mei...
See also
Da und dort...
Form-Method
Name
Form-Method — returns the content of a HTML form variable.
71
Chapter 9. Methods
Synopsis
Return values
Parameters
cName
Specified name attribute of the correspondending input field.
nIndex
Specified index the correspondending input field.
aArray
Specified array to get all form input fields as key/value pair.
Notes
This method maybe a little bit confusing first, but is very powerful. You can achieve your form content
by several ways in three different manners. The easiest call Request.Form() gives you all key/pair values
as a string. Here’s a list about specified parameter and excepted return values:
cForm = REQUEST.Form()
cVar = REQUEST.Form(cName)
cVar = REQUEST.Form(nIndex)
nCount = REQUEST.Form(@aArray)
aForm = REQUEST.Form(0)
72
Chapter 9. Methods
Example
A small exmaple for a recursive HTML formular to represent the inserted value. You can simple
enchance this example by integrating IF EMPTY() statements for the form variable.
<%
lcSearch = Request.Form("search")
%>
<html><head></head><body>
<form action="<%? FILE.cVirtualLocation%>" method="post">
Insert your search string:<br>
<input type="text" size="10" name="search" value="<%? lcSearch%>">
<input type="submit" value=" Go ">
</form>
</body></html>
See also
QueryString-Method
GetCacheName-Method
Name
GetCacheName-Method — returns the name of the file in the %cache% without any extension.
Synopsis
File.GetCacheName( )
Return values
Character
73
Chapter 9. Methods
Parameters
Notes
Example
<%
lcCacheFile = FILE.GetCacheName
? SERVER.HTMLEncode(lcCacheFile)
%>
See also
GetCookieHeader-Method
Name
GetCookieHeader-Method — returns the complete cookie information.
Synopsis
Response.GetCookieHeader( )
Return values
Character
74
Chapter 9. Methods
Parameters
Notes
This methods returns a complete set of all cookie information found in the response buffer.
Example
<%
? Response.GetCookieHeader()
%>
See also
Cookie-Property | AddCookie-Method
GetLocation-Method
Name
GetLocation-Method — returns the actual location for the file, if one exists.
Synopsis
File.GetLocation( )
Return values
Character
75
Chapter 9. Methods
Parameters
Notes
If the file exists in cLocation, this location is returned. Otherwise, cVirtualLocation is determined in the
alternate directory tree (virtual director tree) as defined in the afp.config file. If the file doesn’t exist
there, an empty string is returned. This name is unique for any file in a web site.
Example
This method is useful to refer to relative data files below your public web directory.
<%
lcData = "D.\inetpub\data\customer.dbf"
IF NOT FILE(lcData)
lcData = ADDBS(JUSTPATH(FILE.GetLocation())) + "data\customer.dbf"
ENDIF
IF NOT USED("customer")
USE (lcData) IN 0 SHARED
ENDIF
SCAN
? cust_id + "<br>"
ENDSCAN
%>
See also
cLocation-Property
cVirtualLocation-Property
76
Chapter 9. Methods
GetSessionCookie-Method
Name
GetSessionCookie-Method — returns a cookie string with the current session ID.
Synopsis
Session.GetSessionCookie( )
Return values
Parameters
Notes
If HTTP cookies are enabled, returns a cookie string with the current session ID. This method is
automatically called when the response is send back to the client.
Example
See also
GetSessionData-Method
Name
GetSessionData-Method — returns session data that has previously been saved by
SetSessionData().
77
Chapter 9. Methods
Synopsis
Session.GetSessionData( )
Return values
Character
Parameters
Notes
Example
See also
GetSessionFileName-Method
Name
GetSessionFileName-Method — returns a file name that you can use to store session specific
data.
Synopsis
Session.GetSessionFileName( )
78
Chapter 9. Methods
Return values
Parameters
Notes
cExtension must currently start with a period (.). This method returns a file name that you can use to
store session specific data. These files are stored in the session directory and automatically deleted when
the session times out. The ControlServer checks every 3 minutes for abandoned files and deletes them.
This applies to directories, too. For directories, only the directory name must be returned by this method.
Files in a directory can have any name.
This method is especially usefull to keep temporary results sets, shopping carts, and the like. However,
keep in mind that these files might exist for the duration of a session (30 minutes by default). If you have
many hits, you might run out of harddisk space.
Example
lcDir = GetSessionFileName(".appdata")
Md (lcDir)
Create Database (AddBs(lcDir)+"foo")
See also
Header-Method
Name
Header-Method — returns all additional HTTP header information.
79
Chapter 9. Methods
Synopsis
Response.Header( )
Return values
Character
Notes
The method returns all information set to the HTTP header via AddHeader-Method
Example
<%
*// write additional HTTP-Header.
Response.AddHeader("X-Powered-By", "AFP/3.0")
See also
AddHeader-Method
HTMLDecode-Method
Name
HTMLDecode-Method — converts HTML escape codes back to normal characters.
80
Chapter 9. Methods
Synopsis
Server.HTMLDecode(cValue)
Return values
Character
Parameters
cValue
Encoded string to decode with HTML conversion.
Notes
Tjoa...
Example
lcString = SERVER.HTMLDecode(lcFormVar)
See also
HTMLEncode-Method
HTMLEncode-Method
Name
HTMLEncode-Method — applies HTML escape codes.
81
Chapter 9. Methods
Synopsis
Server.HTMLEncode(cValue)
Return values
Character
Parameters
cValue
Encoded string to decode with HTML conversion.
Notes
CHR(10) is converted to "<br>", all special characters are converted to their "&xxx;" counterparts.
Control characters are removed, eg. CHR(7) or CHR(13). FOX.Out() has been updated to use
SERVER.HTMLEncode(). The configuration table cannot be configured.
Example
lcQuoteString = SERVER.HTMLEncode(lcString)
See also
HTMLDecode-Method
82
Chapter 9. Methods
HTTPCookie-Method
Name
HTTPCookie-Method —
Synopsis
Response.( )
Return values
Parameters
Notes
Example
See also
IsNew-Method
Name
IsNew-Method —
83
Chapter 9. Methods
Synopsis
Session.IsNew( )
Return values
Parameters
Notes
returns .T., wenn SessionID() has created a new session, if no session has yet been created or a session
timed out.
Example
See also
MakePath-Method
Name
MakePath-Method — returns a path.
Synopsis
Return values
Character
84
Chapter 9. Methods
Parameters
cDirectory
...
cFile
...
Notes
If needed, backslashes are added or souble backslashes removed. In both parts you can use any of the
system variables: %root%, %common%, %cache%, %log% and %session%.
Example
See also
MapPath-Method
Name
MapPath-Method —
Synopsis
Server.MapPath( )
Return values
85
Chapter 9. Methods
Parameters
Notes
Example
See also
MultiPart-Method
Name
MultiPart-Method — returns values from multipart-enctyped HTML forms
Synopsis
Return values
Character
Parameters
cName
...
86
Chapter 9. Methods
cElement
Specifies the element property to return from form element cName. Currently two elements are
available:
Notes
The MultiPart-method is useful with any multipart-enctyped HTML forms, ie. to upload files to the
server.
Example
<%
Local lcFileName, lcDescription, lcFile
lcFileName = JustFName(Request.MultiPart("txtFile","filename"))
If Empty(m.lcFileName)
Return
EndIf
lcDescription = Request.Form("edtDescription")
lcFile = Request.Form("txtFile")
87
Chapter 9. Methods
See also
Form-Method
NewSession-Method
Name
NewSession-Method —
Synopsis
Session.NewSession( uSessionID )
Return values
Parameters
uSessionID
Notes
Example
See also
88
Chapter 9. Methods
QueryString-Method
Name
QueryString-Method — returns a variable in the query string.
Synopsis
Return values
Parameters
cKey
Specified key attribute of the correspondending field.
nIndex
Specified index the correspondending field.
aArray
Specified array to get all query infos as key/value pair.
Notes
With this method you can handle the query string of an URL reqeusted by the browser. This is very
useful if you are dealing with enhanced hyperlink definitions to use the same AFP document always the
same time for (slightly) different responses but same static elements.
Formerly FOX.GetPar()
89
Chapter 9. Methods
Example
This example is an extract from the official data-driven AFP website (site.afp):
<%
lcCategory = ALLTRIM(LOWER(Request.QueryString("cat")))
lcCategory = IIF(INLIST(lcCategory, "home", "docu", "demo"), lcCategory, "home")
SELECT * ;
FROM category ;
WHERE cCat == (lcCategory) ;
INTO CURSOR _Category
IF _TALLY > 0
SCAN
SCATTER MEMO MEMVAR
? m.de + "<p>"
GATHER MEMO MEMVAR
ENDSCAN
ENDIF
%>
See also
Form-Method | ServerVariables-Method
Redirect-Method
Name
Redirect-Method — redirects the client’s browser to another location.
Synopsis
Response.Redirect( cLocation )
Return values
90
Chapter 9. Methods
Parameters
cLocation
Notes
The Redirect method generates a HTTP 302 message with the new location and sends this back to the
client’s browser. In consequence the browser requests the new URL automatically.
Example
Due to some re-structuring your Web site has other paths and/or filenames.
<%
? Response.Redirect("newpage.afp")
See also
Relative-Method
Name
Relative-Method — returns a new file object that represents a file in a position relative to the
current one.
Synopsis
File.Relative( cRelativeLocation )
Return values
Object
91
Chapter 9. Methods
Parameters
cRelativeLocation
Location to another file relative to the current one.
Notes
The relative location is searched in both trees - the physical and the virtual one.
Example
If you need a standard footer at the end of your page this might be done with this method.
<%
loFooter = FILE.Relative("includes/footer.inc.htm")
lcFooter = FileToStr(loFooter.GeLocation())
? lcFooter
%>
See also
Clone()
ReNew-Method
Name
ReNew-Method — updates the time stamp for the current session.
Synopsis
Session.Renew( )
92
Chapter 9. Methods
Return values
Parameters
Notes
Example
See also
Reset-Method
Name
Reset-Method — loads the file object with its location properties.
Synopsis
Return values
Parameters
cLocation
Physical location of the File object.
93
Chapter 9. Methods
cVirtualLocation
Virtual location of the File object.
cHost
Hostname of the Web site to handle the object.
Notes
This method sets the properties for the physical and virtual paths. It’s actually used internal by the file
methods Clone() and Relative().
Example
See also
Clone-Method | Relative-Method
Reset-Method
Name
Reset-Method — reloads the internal collections of the request object
Synopsis
Request.Reset( )
Return values
Parameters
94
Chapter 9. Methods
Notes
The Reset-Method reloads the internal collections for the request methods Form(), QueryString(),
Cookies() and ServerVariables() and the request properties cData and cForm.
Example
See also
Reset-Method
Name
Reset-Method — resets the response to its defaults.
Synopsis
Response.Reset( )
Return values
Parameters
Notes
Resetting the Response object includes the HTTP header with status code, cookie information, the
content type and the content itself.
95
Chapter 9. Methods
Example
<%
Response.Reset()
%>
<html><body>New content to respond...</body></html>
%>
See also
Clear-Method
ResolveRelative-Method
Name
ResolveRelative-Method — returns an absolute path that is relative to the specified base.
Synopsis
Return values
Character
Parameters
cBase
Specifies the base to start from to resolve the relative path to the destination. This can be a file or a
path.
96
Chapter 9. Methods
cRelative
Specifies the relative path to the destination.
Notes
Example
<%
lcAbsPath = FILE.ResolveRelative(FILE.GetLocation(), "../images")
%>
<img src="<%? lcAbsPath%>/afplogo.png" border="0" alt="AFP Logo">
See also
ServerVariables-Method
Name
ServerVariables-Method — returns any of the HTTP server variables.
Synopsis
Return values
97
Chapter 9. Methods
Parameters
cKey
Specified key attribute of a known server variable.
nIndex
Specified index inside the array of server variables.
aArray
Specified array to get all server variables as key/value pair.
Notes
This methods gives you all informations send by the web server to the AFP documents. With
ServerVariables() are able to inter- and re-act with user specific informations sent by their browser
everytime. Also it’s possible to get informations about the web server software itself, i.e. to handle web
server specific extensions or features.
Example
<%
gcLang = "en" && default language
DO CASE
CASE lcLang = "de"
? "Guten Tag"
CASE lcLang = "en"
? "Hello"
CASE lcLang = "fr"
? "Bonjour"
OTHERWISE
? "Undefinied" && or something else...
ENDCASE
%>
98
Chapter 9. Methods
This example determines the information about the web server software:
<%
? Request.ServerVariables("SERVER_SOFTWARE") && Apache 2.0.43(Win32)
%>
See also
CData-Property
SessionID-Method
Name
SessionID-Method — returns the current session ID.
Synopsis
Session.SessionID()( )
Return values
Parameters
Notes
If needed a new session is created. The default session ID is a 44 character string that bases on GUIDs
and therefore is unique. With the C24_Cookie PlugIn installed, a SYS(2015) string is returned.
99
Chapter 9. Methods
Example
See also
SetSessionData-Method
Name
SetSessionData-Method — makes the string in cData available for future instances of this session.
Synopsis
Session.SetSessionData( )
Return values
Parameters
Notes
Technically, a ".session" file is generated in the session directory. This method is used to save variables.
The result of SAVE MEMORY ALL LIKE G* is passed as the cData. You can use this function to store
additional variables, or other temporary data like XML strings. cID should be a unqiue string. It shares
the name space with the application IDs.
Example
100
Chapter 9. Methods
See also
Timeout-Method
Name
Timeout-Method — returns or changes the remaining time until the session is discarded.
Synopsis
Session.Timeout( [ nMinutes ] )
Return values
Numeric
Parameters
Notes
With the Timeout-Method you are able to get the remaining time until the current session is discarded
and by specifying a numeric value to set this timeout in minutes.
Example
Give feedback to the user when its session will be terminated by the server.
101
Chapter 9. Methods
For an online editing interface it might be useful to increase the timeout value after the user logged in
successful.
<%
lnMinutes = 60
Session.Timeout( lnMinutes )
%>
Welcome, you are authorized.
<p>Please remember that you will be logged off automatically after
<%? lnMinutes%> minutes inactivity.
<p>Happy working!
See also
Transfer-Method
Name
Transfer-Method — transfers execution to another document after the current document terminated.
Synopsis
Server.Transfer( cFile )
Return values
Parameters
cFile
Notes
The result of the called page is added to the response buffer, effectively merging both pages together.
You can chain as many pages together as you want. The called page is not executed immendiately, but
102
Chapter 9. Methods
only after finishing the current one. Inside an .afp document, you can use RETURN to cancel execution.
When multiple SERVER.Transfer() calls are made in a page, the last one wins.
Example
<%
? "Hello, this is the actually called page.<br>"
? "We are now moving to a second AFP document to response...
Server.Transfer("rest.afp")
%>
See also
URL-Method
Name
URL-Method — returns a URL string that contains the SessionID.
Synopsis
Session.URL( )
Return values
Parameters
Notes
The format depends on the session object. The default object generates:
103
Chapter 9. Methods
You should replace all occurrences of ?FOX.cCookie inside a URL to this new syntax, because it allows
the transition to the new unique session ID.
Example
Session.URL("info.afp","name=foo")
See also
URLDecode-Method
Name
URLDecode-Method — decodes a string that has been URL encoded.
Synopsis
Server.URLDecode( cValue )
Return values
Parameters
cValue
Encoded string to decode with URL conversion.
104
Chapter 9. Methods
Notes
This means that certain characters have been replaced by a percent sign followed by their hex ASCII
code. For eample, "AFP 3.0" is encoded "AFP%203.0". Passing the last string as a parameter to this
method results in the first string. This method is used to decode form data or query parameters.
Example
See also
URLEncode-Method
URLEncode-Method
Name
URLEncode-Method — encodes a string to be used in an URL.
Synopsis
Server.URLEncode(cValue)
Return values
Parameters
cValue
String to encode with URL conversion.
105
Chapter 9. Methods
Notes
Example
See also
URLDecode-Method
Version-Method
Name
Version-Method — returns the version information of the Active FoxPro Pages.
Synopsis
Server.Version()
Return values
Character
Parameters
Notes
Example
106
Chapter 9. Methods
See also
Write-Method
Name
Write-Method — returns content to the browser.
Synopsis
Response.Write( uValue )
Return values
Parameters
uValue
Value to response to the browser as result of the requested URL.
Notes
The Write-Method is responsible for any content send back to the browser. In analogy to other web
products the method can also be used like this: ’? uValue’ and/or ’= uValue’.
All data-types are allowed as parameter. The method converts them internal to strings.
Example
<%
107
Chapter 9. Methods
Response.Write("Hello World")
? 40 + 2
= DATETIME()
%>
See also
108
III. Appendixes
--
Appendix A. Multi-thread Restrictions of VFP
The multi-thread environment of AFP 3.0 offers a lightweight run-time library for in-process servers,
many user-input commands and functions are removed. All Object syntax is still available, though events
from visual classes such as forms are disabled. The following language categories of Microsoft Visual
FoxPro are removed from AFP3Engine.dll:
110
Appendix A. Multi-thread Restrictions of VFP
111
Appendix A. Multi-thread Restrictions of VFP
DOEVENTS
SET ASSERTS SET BELL SET BORDER
112
Appendix A. Multi-thread Restrictions of VFP
113
Appendix B. AFP License Agreement
This is a legal agreement between you, the User, and ProLib Software GmbH of Seebruck, Germany. If
you do not agree to the terms of this agreement, promptly return the disks and the accompanying written
ma-terials, binders, and other containers (’the Documentation’) in original condition to the place where
you obtained them for a full refund within 30 (thirty) days of purchase. By opening this package you
agree to these terms.
B.1. License
ProLib Software GmbH hereby grants to you a non-exclusive license (’the License’) to use the
Documentation and for one person at one time to use one copy of the ProLib Software GmbH software
program accompanying this License (’the Software’) on a single computer (’Dedicated Computer’).
B.2. Copyright
ProLib Software GmbH and its suppliers retain all rights, title and interest in and to the Software and the
Documentation including all copyrights. The Software and the Documentation are protected under the
copyright laws of Germany and international agreements and treaty provisions. There are severe
penalties, both civil and criminal, for copyright infringement. You may transfer the Software to a hard
disk and keep up to three copies of the Software, including the original copy, solely for back-up or
archival purposes. You may not copy the documentation.
You may not rent, lease, or in any other manner make the Software available to third persons. You may
not modify, reverse engineer, decompile or disassemble the Software. You may transfer your rights under
this License to a third person on a permanent basis provided you transfer the Software and all
Documentation, retain no copies, and the re-cipient agrees to and accepts the terms of this License
Agreement.
In no event will ProLib Software GmbH or its employees, agents, or suppliers be liable for any damages
arising out of the User or the inability to use the Software or Documentation, including, but not limited
to, any damages for lost profits or anticipated benefits, even if they have been advised of the possibility
of such damages.
B.4. Validity
This License Agreement is governed by the pertaining laws of the Federal Republic of Germany and of
114
Appendix B. AFP License Agreement
the European Union and is regarded under these laws as a valid contract between both parties, even if not
signed and sealed. This License Agreement constitutes the entire agreement between the User and
ProLib Software GmbH concerning the Software and the Documentation. There are no other agreements,
understandings or conventions, written or oral, between ProLib Software GmbH and you with respect to
this Software and Documentation; if they existed prior to the purchase, they are superseded by this
License Agreement. No ProLib Software GmbH employee, agent, or dealer is authorized to make any
amendment to this agreement.
B.5. Contact us
Should you have any questions concerning this License Agreement, the Software or the Documentation,
you may contact us by writing to
115
Glossary
[This topic is part of a beta release and is subject to change in future releases. Blank topics are included
as placeholders.]
A
Active FoxPro Pages
Script engine created by ProLib Software GmbH based on Microsoft Visual FoxPro to enable
HTML pages to be dynamic and interactive by embedding scripts. Since the scripts in AFP pages
(suffix .afp) are processed by the server, any browser can work with AFP regardless of its support
for the scripting language used therein.
See Also: Visual FoxPro.
C
Cursor
D
Database
116
Glossary
E
Extensible Markup Language
XML is the Extensible Markup Language, a system for defining specialized markup languages that
are used to transmit formatted data. XML is conceptually related to HTML, but XML is not itself a
markup language. Rather it’s a metalanguage, a language used to create other specialized languages.
F
File Transfer Protocol
This Internet protocol is used to copy files between computers--usually a client and an archive site.
It’s old-fashioned, it’s a bit on the slow side, it doesn’t support compression, and it uses cryptic Unix
command parameters. But the good news is that you can download shareware or freeware apps that
shield you from the complexities of Unix, and you can connect to FTP sites using a Web browser.
H
Hypertext Markup Language
As its name suggests, HTML is a collection of formatting commands that create hypertext
documents--Web pages, to be exact. When you point your Web browser to a URL, the browser
interprets the HTML commands embedded in the page and uses them to format the page’s text and
graphic elements. HTML commands cover many types of text formatting (bold and italic text, lists,
headline fonts in various sizes, and so on), and also have the ability to include graphics and other
nontext elements.
The protocol used to transmit and receive all data over the World Wide Web. When you type a URL
into your browser, you’re actually sending an HTTP request to a Web server for a page of
information (that’s why URLs all begin with "http://"). HTTP1.1, the latest version, is currently
undergoing revisions to make it work more efficiently with TCP/IP
117
Glossary
I
Internet Information Services
Internet Information Server, Web-server, part of the Windows NT Server, supports ISAPI.
IP
Internet Protocol, protocol in the TCP/IP internet layer for communication between nets and their
hosts. An IP-address uniquely identifies each network and each of its hosts on the internet.
Addresses consist of four bytes that can be represented by four integers (0 to 255) seperated by dots,
e.g. "157.189.162.75". Dependent on the address’ class and a subnet mask, a specific number of bits
identify the net or subnet and the rest a PC’s address within this net/subnet.
ISAPI
Internet Information Server API, API supported by the MS’s Internet Information Server (IIS).
R
Request
Response
Rushmore
T
Thread
118
Glossary
V
Visual FoxPro
W
World Wide Web
Also known as the WWW, the W3, or most often simply as the Web, it originally developed by
CERN labs in Geneva, Switzerland. Continuing development of the Web is overseen by the World
Wide Web Consortium. The Web can be described (dryly) as a client/server hypertext system for
retrieving information across the Internet. On the Web, everything is represented as hypertext (in
HTML format) and is linked to other documents by their URLs. The Web encompasses its native
http protocol, as well as ftp, Gopher, and Telnet. The best way to learn about it, however, is to try it
for yourself.
119
Index
120