Enter image characters:
Opcionals fields
Enter name:
Enter last name:
Enter email:
Highlight HTML code
<% '' Please, dont't remove this '' Code By Juan C. Barreiro '' EnterpriseDreams Solutions '' www.enterprisedreams.net Function Captcha(l) Dim a(), b(), c, d, e, g, n g="a,b,c,d,e,f,g,h,i,j,k,l,m," g=g&"n,o,p,q,r,s,t,u,v,w,x,y,z," g=g&"A,B,C,D,E,F,G,H,I,J,K,L,M," g=g&"N,O,P,Q,R,S,T,U,V,W,X,Y,Z," g=g&"1,2,3,4,5,6,7,8,9,0" d=Split(g,",") Redim a(l-1) : Redim b(l-1) : c=0 : Randomize Do Until c=l : n=Int(Rnd*Ubound(d)) : b(c)=n : a(c)=d(n) : c=c+1 : Loop e=Join(a,"") : Session("captcha_code")=e Set Jpeg = Server.CreateObject("Persits.Jpeg") Jpeg.Open Server.MapPath("/images/transparent.gif") Jpeg.Width = Int((l*15)+40) Jpeg.Height = 50 Jpeg.Canvas.Font.Color = &HFF0000 Jpeg.Canvas.Font.Family = "Courier New" Jpeg.Canvas.Pen.Color = &H000000 Jpeg.Canvas.Pen.Width = 2 Jpeg.Canvas.Brush.Solid = False Jpeg.Canvas.PrintText 10, 10, e Jpeg.Canvas.DrawBar 1, 1, (l*15), 40 Jpeg.SendBinary Set Jpeg = Nothing End Function ' display image captcha and make a new session value ' any number of characters work ' (use 5 to 7 max for user usability) ' i have tested with 50+ alphanumerics characters and display very well Response.Write Captcha(7) %>
<% If Request.ServerVariables("REQUEST_METHOD") = "POST" Then If Request.Form("captcha_code") <> Session("captcha_code") Then Response.Write "<p>Your captcha code is not valid.</p>" Response.Write "<p><a href=javascript:history.go(-1)>Try again</a></p>" Else '' put here your code For Each Item In Request.Form If Not Item = "captcha_code" Then Response.Write "<p>" & Item &" = "& Request.Form(Item) & "</p>" End If Next '' at the end empty session to prevent re-send the form Session.Contents.Remove("captcha_code") End If Else%>
<html> <head> <title>Captcha Live demo (letters are case sensitive)</title> </head> <body> <h1>A simple Captcha using ASPJpeg and VbScript</h1> <p><img src="captcha.asp"></p> <form action="yourpage.asp" method="post"> <p>Enter image characters:<input type="text" name="captcha_code" value=""></p> <p>Opcionals fields</p> <p>Enter name:<input type="text" name="name" value=""></p> <p>Enter last name:<input type="text" name="last_name" value=""></p> <p>Enter email:<input type="text" name="email" value=""></p> <p><input type="submit" value="submit"></p> </form>
<%End If>
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 Spain License. ASPJpeg is a commercial component from Persits software
© 2006 - Juan C. Barreiro Web Engineer Developer