Bare Bones example of the LylaCaptcha

Here is a quick, dirty and bare bones example of the LylaCaptcha using the stream method. This is for my own notes, but if you find it handy you are welcome to it. This example is very highly based on Brian Rinaldi Ajax example (just sans Ajax and it does not use the file method):
http://www.remotesynthesis.com/blog/index.cfm/2006/6/21/Validating-CAPTCHA-with-AJAX

http://coldfusion.sys-con.com/read/236003.htm 

A few items of note:
-The stream method requires CF7.
-LylaCaptcha should be init'ed into a persistent scope (Application scope) Or else the hashes will not match.
-The form page assumes captchaimg.cfm is the Captcha generation page.
-All paths assume this example is in the "captcha" folder. (Not a good idea to do this in production.)
-All three files below AND LylaCaptcha are required for this example to work.

 Here is the code:

Application.cfm:

<cfapplication name="LylaCaptchaApp">
<cfparam name="url.reinit" default="false">
<!--- initalize the  LylaCaptcha--->
<cfif not structKeyExists(application,"captcha") or url.reinit>
    <cfset application.captcha = CreateObject("component","captchaService").init(configFile="captcha.xml") />
    <cfset application.captcha.setup() />
</cfif>

 

 form.cfm:

 <!--- If form is submitted validate Captcha hash and user input--->
<cfif isdefined("form.fieldnames") >
    Captcha Valid:<cfdump var="#application.captcha.validateCaptcha(form.captchaHash,ucase(form.captchaText))#">
</cfif>

<!--- Build Hash to pass to the image file and to pass in the hidden form field--->
<cfset variables.captcha = application.captcha.createHashReference() />

<html>
<body>
<cfoutput>
<form method="post" action="#GetFileFromPath(cgi.script_name)#">
    <!--- call image file. Send Hash --->
     <img src="captchaimg.cfm?hashReference=#variables.captcha.HASH#" />
     <!--- Input text box for user input --->
    <input type="text" name="captchaText" size="6"  value=""/>
     <!--- Hidden Input text box for hash --->
    <input type="hidden" name="captchaHash" value="#variables.captcha.hash#" />
    <input Type="submit" name="go" value="go">
</form>
</cfoutput>
</body>
</html>

 captchaimg.cfm:

<cfset variables.captcha = application.captcha.createCaptchaFromHashReference("stream",url.hashReference) />
<cfcontent type="image/jpg" variable="#variables.captcha.stream#" reset="false" />

Comments
Brian Rinaldi's Gravatar Good work! and thanks for the links...though the first one isn't working for some reason.
# Posted By Brian Rinaldi | 9/27/06 2:19 PM
Mark W. Breneman's Gravatar Thanks Brian,

Doh, egg on my face.... I had a random '<' in the attribuite action of the form.

Thanks for finding that. Code above has been updated.
# Posted By Mark W. Breneman | 9/27/06 2:30 PM
Rod Kesselring's Gravatar I am sorry to ask this but I have tried to use your example on my web server and i keep getting a null pointer exception have you seen this problem before. I can get it to work flawless on my home production server but on my host server I cant. I can't seem to get any CFC to work on the server but since they have robust turned off all i see is a java null pointer exception. any help would be greatly appreciated.
# Posted By Rod Kesselring | 10/12/06 3:49 PM
Mark W. Breneman's Gravatar Hello Rod,

First can you confirm the version of CF you are running on your webserver?

MB
# Posted By Mark W. Breneman | 10/12/06 3:52 PM
Rod Kesselring's Gravatar yes it is mx7.01 I found some info about beople using hotfix 2 but they said it meant thay had to totally reinstall teh server and i don't think my host would be too happy about that since it is a shared server :(
# Posted By Rod Kesselring | 10/12/06 4:16 PM
Mark W. Breneman's Gravatar Looks like you have the same problem that I had a while back.
http://www.dervishmoose.com/blog/index.cfm/2006/3/...

Seems to me heard about the ColdFusion MX 7 Updater 2 (7.0.2)fixing the issue. At least a good idea to start with asking you hosting provider to upgrade.

Sorry I could not be more help.
# Posted By Mark W. Breneman | 10/12/06 5:24 PM
Rod Kesselring's Gravatar Mark,
As it is my understaning your issue happened when they applied the fix and had to rollback in order to fix the issue. Is that correct?
My host company shows version 7,0,1,116466 which would mean that they have not applied the hotfix yet. So applying the hotfix would create more issues than less. Am i correct in this assumption? Sorry to drag this out just trying to understand the issue.
# Posted By Rod Kesselring | 10/13/06 9:28 AM
Mark W. Breneman's Gravatar Rod I'm sorry, maybe I am giving some bad advice. Is updator 2 the same as hot fix 2 that seems to be causing the problmes? I was under the impression that the hot fix 2 predated Updator 2. But, maybe they are the same thing.

Better check Adobes site (help fourm)

Sorry I could not be more help.

MB
# Posted By Mark W. Breneman | 10/13/06 10:37 AM
Dave's Gravatar Well, I'm trying to run a test on my organization's site. And I'm really not even sure what ColdFusion set-up they have, but here is the form.cfm page:
http://www.aigaphilly.org/captimg/test03/form.cfm

It's giving me a "Variable IsXML is undefined." error? Does that look familiar?
# Posted By Dave | 11/7/06 4:27 PM
Brian Rinaldi's Gravatar isXML was added in CF7, so my guess is that they are running 6.x. There is an isXML function I believe at cflib.org, but be aware that this will cause an error if and when you upgrade to 7 (because you cannot have two function with the same name). Also, I cannot remember if LylaCAPTCHA was designed to support 6 or not...I didn't see it on the site in a quick check, so you might want to check with Peter.
# Posted By Brian Rinaldi | 11/7/06 4:42 PM
Mark W. Breneman's Gravatar You could try #server.coldfusion.productversion#. That should tell you what version of CF server you are running.

Also, if you don't have version 7 you can not use the stream method (as in my example) for displaying the image.

You will have to use the file medthod assuming LylaCAPTCHA (see link) will run on CFMX 6. I can not find any info to say if it will or if it will not.

http://lyla.maestropublishing.com/FAQ.cfm#15
# Posted By Mark W. Breneman | 11/7/06 8:14 PM
santshos's Gravatar All greetings! My name is Tom. I from Kentwood, Louisiana. I the big admirer Britney Spears. I consider as the duty to distribute the information on this surprising singer, an actress and simply mother. I can share with you interesting clauses on following sites:
http://www.britany-spears.150m.com/britany-spears.... , Cool site!
# Posted By santshos | 4/16/07 12:23 PM
Haseeb Khan's Gravatar Hi All,

Can anyone please specify that LylaCaptcha works on ColdFusion 6.1 or not? I am facing many issues with that.

If it works, it would be great if a step-by-step guide can be provided for beginners like me.

Any help would be highly appreciated.

Thanks and Regards,

Haseeb Khan
# Posted By Haseeb Khan | 6/6/07 2:38 PM
newsblogdirect's Gravatar Thanks for posting
interesting site
http://newsblogdirect.com
# Posted By newsblogdirect | 4/9/08 6:56 AM
watch divx film  online's Gravatar Thousands of hot movies that you dare to watch. Movies are playable on various devices including iPod, PDA (HandHelds), PC, DVD & DivX players. Lowest prices on the web ever. Start downloading movies from $1.99 only! Absolutely no limits. You can download as much as you want with incredibly high speeds. No additional software required. Click on a link, download a movie and watch it on your favourite player.
http://timbei.info
# Posted By watch divx film online | 4/14/08 5:23 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.001. Contact Blog Owner