Bare Bones example of the LylaCaptcha

ColdFusion Add comments

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" />

13 responses to “Bare Bones example of the LylaCaptcha”

  1. Brian Rinaldi Says:
    Good work! and thanks for the links...though the first one isn't working for some reason.
  2. Mark W. Breneman Says:
    Thanks Brian,

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

    Thanks for finding that. Code above has been updated.
  3. Rod Kesselring Says:
    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.
  4. Mark W. Breneman Says:
    Hello Rod,

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

    MB
  5. Rod Kesselring Says:
    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 :(
  6. Mark W. Breneman Says:
    Looks like you have the same problem that I had a while back.
    http://www.dervishmoose.com/blog/index.cfm/2006/3/16/Problems-with-CFMX-701-Hot-Fix-2-and-CFCs

    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.
  7. Rod Kesselring Says:
    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.
  8. Mark W. Breneman Says:
    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
  9. Dave Says:
    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 &quot;Variable IsXML is undefined.&quot; error? Does that look familiar?
  10. Brian Rinaldi Says:
    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.
  11. Mark W. Breneman Says:
    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
  12. santshos Says:
    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.html , Cool site!
  13. Haseeb Khan Says:
    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

Leave a Reply




Powered by Mango Blog. Design and Icons by N.Design Studio