博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
captcha.php_简单的ASP.NET CAPTCHA
阅读量:2535 次
发布时间:2019-05-11

本文共 2622 字,大约阅读时间需要 8 分钟。

captcha.php

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages.

我将向您展示如何在不使用任何HTTP HANDELRS的情况下创建ASP.NET Captcha控件。 您可以轻松地将其插入网页。

For Example

例如

a = 2 + 3 (where 2 and 3 are 2 random numbers)

a = 2 + 3(其中2和3是2个随机数)

Session("Answer") = 5

会话(“答案”)= 5

then we will create a image using System.drawing namespace with the text " 2+ 5 = " within it. We will store the result into a session variable, so later on our webpage we can use this session variable to compare with what user types.

然后我们将使用System.drawing命名空间创建一个图像,其中包含文本“ 2+ 5 =”。 我们会将结果存储到会话变量中,因此稍后在我们的网页上,我们可以使用该会话变量与用户类型进行比较。

Lets see the code of Captcha.aspx:

让我们看一下Captcha.aspx的代码:

Imports System.DrawingPartial Class Captcha    Inherits System.Web.UI.Page     Private Sub returnNumer()        Dim num1 As New Random        Dim num2 As New Random        Dim numQ1 As Integer        Dim numQ2 As Integer        Dim QString As String        numQ1 = num1.Next(10, 15)        numQ2 = num1.Next(17, 31)         QString = numQ1.ToString + " + " + numQ2.ToString + " = "        Session("answer") = numQ1 + numQ2        Dim bitmap As New Bitmap(85, 35)        Dim Grfx As Graphics = Graphics.FromImage(bitmap)        Dim font As New Font("Arial", 18, FontStyle.Bold, GraphicsUnit.Pixel)        Dim Rect As New Rectangle(0, 0, 100, 50)        Grfx.FillRectangle(Brushes.Brown, Rect)        Grfx.DrawRectangle(Pens.PeachPuff, Rect) ' Border        Grfx.DrawString(QString, font, Brushes.Azure, 0, 0)        Response.ContentType = "Image/jpeg"        bitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)        bitmap.Dispose()        Grfx.Dispose()     End Sub    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load        Call Me.returnNumer()    End SubEnd Class

So the Page_Load event generates an image.

因此,Page_Load事件生成一个图像。

Now we can use this Page within any aspx page for verification. For Example here is form2.aspx

现在,我们可以在任何aspx页面中使用此页面进行验证。 例如,这里是form2.aspx

<asp:image runat=server imgeurl="captcha.aspx">

<asp:image runat = server imgeurl =“ captcha.aspx”>

now you can create a TextBox, have users enter some text into it, and then create a ANSWER button, upon clicking of ANSWER button compare the value of textbox with the Session variable Session("answer"), if both are same then Verification passed.

现在,您可以创建一个TextBox,让用户在其中输入一些文本,然后创建一个ANSWER按钮,单击ANSWER按钮后,将文本框的值与会话变量Session(“ answer”)进行比较,如果两者相同,则验证通过。

Any questions please post below.

如有任何疑问,请在下面发布。

Thanks for reading.

谢谢阅读。

翻译自:

captcha.php

转载地址:http://cjhzd.baihongyu.com/

你可能感兴趣的文章
mvn install selenium依赖包
查看>>
关于SQL的相关笔记【长期更新,只发一帖】
查看>>
linux awk命令详解
查看>>
android:id="@+id/button1" 与 android:id="@id/button1" 区别 @string
查看>>
手把手玩转win8开发系列课程(11)
查看>>
Linux Namespace : User
查看>>
交换两个整形变量的数值
查看>>
Linux----常用操作
查看>>
sequence
查看>>
Delphi错误:Stack overflow的解决方法
查看>>
一篇很全面的freemarker教程
查看>>
取消chrome(谷歌浏览器)浏览器下最小字体限制
查看>>
模板方法模式
查看>>
什么是ECC内存?
查看>>
使用Visual Studio 2013进行UI自动化测试
查看>>
13-集体照
查看>>
读了曾国藩家书,,心态逐渐平和起来。搞技术的如果缺乏信念的指引,生活会很乏味无聊!...
查看>>
前端javascript 错误 Uncaught SyntaxError: Unexpected token ILLEGAL
查看>>
Selenium WebDriver问题--无法打开Chrome浏览器
查看>>
2017.4.18 Java的Integer与int互转
查看>>