ColdFusion TIPS PLUS
Issue 00096 http://www.cftipsplus.com
I. My CommentsII. ColdFusion In Context: Web Bug
By R. Martin Ladner
martin.ladner@knology.net
See our sponsors at the bottom of this e-mail.
I. Comments:
Keep Coding,
Nathan Stanford
http://www.cftipsplus.com
If you have suggestions for articles send them to us.
If you would like to write for cftipsplus.com
send us an email to:
admin@cftipsplus.com
IF YOU WANT TO BE AN AUTHOR SEND IN YOUR COLDFUSION TIPS.
Remember this is a great way to get your name known in the
ColdFusion Community.
Advanced, Intensive ColdFusion Training!Visit this site. If you have plans to get training here is a company that provides Advanced, Intensive ColdFusion Training. Check them out.
http://www.coldfusiontraining.com/index.cfm?ref=cftipsplus
II. ColdFusion in Context: Web Bug
By R. Martin Ladner
martin.ladner@knology.net
Suppose you want to provide browser statistics for someone who uses a
"dumb" Web host, but you don't want to be deeply involved in writing pages for or managing that site. A Web bug can help.
First, let's clarify things. This tip will not tell you how to retrieve the content of someone's E-mail (through an exploit of the same name). This tip explores possibilities of a technique for limited communication with a page or document from possibly another domain.
Overview
The overall technique presented here is to designate a ColdFusion page as the source for an image or sound, have that page do something useful in the background, and then have that page send content that it has marked as an image or sound as appropriate. You'll turn off all output except ColdFusion output, do your business, use the cfcontent tag to pass this non-text content, and enable normal output again. Everything useful must be accomplished prior to the cfcontent tag; because, the browser stops caring after the image has been received. Its job is done.
Log
Here's some simple code - call it log.cfm - that can be used to track the progress of sessions from the time an individual enters a site unthe profile of sessions an individual's progress through a site. Because no expiration date is given to the cookie, it will vanish when the user closes the browser, but a logical session can be inferred from the data, nevertheless. (Commercial applications typically set a "permanent" cookie which they eventually associate with a userid if a user actually logs into your site.)
It performs the functions named in the overview. First, it enables ColdFusion output only. Then, it checks to see if the cookie identifying a session exists. If not, it sets it to a unique value using the createUUID function. It then gathers information for the log: this ID, the IP address, the full name by which this link was called, any more information following a question mark in that URL (if anything), and the current date and time. In determining the current date/time, it sets a variable to the current date and time first so that the time won't be seconds behind the date. It spits all this information into a log, displays an image, and turns normal output back on. Note that the content type must be appropriate for the content: gif for gif, jpeg for jpg, and so forth.
<cfsetting enablecfoutputonly="yes">
<cfif not isDefined("cookie.webbug")>
<cfcookie name="webbug" value="#createUUID()#">
</cfif>
<cfset id="#cookie.webbug#">
<cfset ip="#cgi.remote_addr#">
<cfset link="#cgi.script_name#">
<cfset more="#cgi.query_string#">
<cfset dt=now()>
<cfset when="#dateformat(dt)# #timeformat(dt)#">
<cfset doline="#id#:#ip#:#link#:#more#:#when#">
<cffile action="append" file="d:\mysite\webbug\log.txt" output="#doline#" addnewline attributes="normal">
<cfcontent type="image/jpeg" file="d:\mysite\webbug\world3.jpg">
<cfsetting enablecfoutputonly="no">
Embed
Now embed calls to this log as "image" requests in normal pages. Each call will look something like this. It looks quite ordinary except that the URL ends in .cfm instead of .gif or .jpg.
<img src="http://mysite.com/webbug/log.cfm">
Mysteries
The idea behind logging the URL (with extra path information) and the query string (everything after the question mark) is to let the calling site provide more information if desired. For example, the query string or extra path information (or both) could be deliberately varied by the maintainer when adding the call. (A call to log.cfm?page=home would work just as well as a plain call to log.cfm.)
When you run this code, it works. However, it winds up creating a cookie that is only noticed by log.cfm, and then only in the context of the call. If you try to see the cookie from the page that called log.cfm, it won't be there. If you try to see the cookie from the site that hosts log.cfm, it won't be there, either. It is as if this cookie can only be seen in the cross-domain context in which it was set. If a user browses multiple sites containing this call to log.cfm, log.cfm will give each site a separate cookie. This quirk makes it hard to envision more useful roles for this Web bug. It can track sessions for a single site, but it doesn't lend itself yet to tracking the same user across different sites.
Determine workarounds for its apparent limitations, and then let us know what you've done.
=Marty=
SPONSOR ADS:
This e-mail is sponsored by the following ads.
Sponsored Ad
IT'S A WEB DEVELOPER'S DREAM COME TRUE
The book on Aestiva's web-based development engine
is here. Build web-based text editiors in ten lines
or less. Build shopping carts with a couple dozen
lines of code. Build database-driven apps in about
the time it takes you to do your laundry! Get the
book ADVANCED WEB SITES MADE EASY. For more info
please visit:
http://dev.aestiva.com/amazon/htmlostips.html
Sponsored Ad
Looking for other development resources?
Visit
http://www.htmlostips.com, a site dedicated
to HTML/OS, a the next generation development
environment that many are saying is the next
generation to Java.
Sponsored Ad
Publisher and Creator:
Nathan Stanford,
admin@cftipsplus.com
http://www.cftipsplus.com
Macromedia and ColdFusion are U.S. registered trademarks.
Copyright (c) 2000 - 2001 CFTIPSPLUS.COM and NSND.COM
Permission is granted to circulate this publication via
MANUAL forwarding by email to friends provided that the text is
forwarded in its entirety and no fee is charged.