I wanted to get a picture into my blog, which isn’t run by my web site. It actually gets posted to 2 URLs: http://blogs.msdn.com/calvin_hsia or at http://weblogs.asp.net/calvin_hsia
I can view and edit my entry in HTML, so I just added an IMG HTML tag pointing to an image on my web site.
Because my web site is actually a computer fully under my control, it counted the number of requests for the picture. It also noted the source of the request (the HTTP_REFERER) and does a SQL Insert to log the data into a Visual FoxPro database.
The web site just has a simple .ASP page with a simple script to invoke a VFP program called DISPATCH.PRG, passing the 3 IIS server objects Request, Response and Server.
This is the entire ASP script:
set session("ox") = server.CreateObject("t1.c1")
set ox = session("ox")
ox.mydocmd("set path to " + request.servervariables("APPL_PHYSICAL_PATH"))
The t1.c1 object has only a couple lines of VFP code. This is the entire code:
DEFINE CLASS c1 as session olepublic
proc MyDoCmd(cCmd as string,p2 as Variant,p3 as Variant,p4 as Variant,p5 as Variant) helpstring 'Execute a command'
proc MyEval(cExpr as string,p2 as Variant,p3 as Variant,p4 as Variant,p5 as Variant) helpstring 'Evaluate an expression'
The “&” is a macro expansion which means to interpret the value as an executable string. Thus the Dispatch cmd expands to:
RETURN Dispatch(request, response, server,0)
The Clear Program command allows me to change the server code without shutting it down.
The Dispatch program just returns an HTML string (or it can do a response.redirect)
FoxPro’s powerful text manipulation and local database engine combine to make serving web pages simple.
For more information, here’s a 1996 article I wrote on using VFP to serve up web pages and my 2001 article on Microsoft Visual FoxPro and Advanced COM