如何在我的HTML弹出窗口中使用验证码

时间:2014-08-11 13:35:50

标签: javascript html asp-classic captcha

我想在我的HTML弹出窗口中使用验证码,我在网上找到了一个简单的验证码,但是我如何编写if语句以确保该人无法在他之前按下“同意”按钮解决了验证码?我如何参考验证码asp文件?

我在HTML中使用的部分代码:

<div style="position:relative; width :100%; height:140px;" >
    <iframe id="captcha" class="ato" src="captcha/test.asp" style="position:relative; width:100%; height:140px;background: linear-gradient(to top, #F9DEB1 0%, #FFFFFF  70%);border-color: #ECD3C4; border-width: 2px; border-style: solid;border-radius:30px;"></iframe>    
</div>

注意:我检查了if,但是如何引用我的html文件之外的asp文件中的布尔值?

ן»¿<%@LANGUAGE="VBSCRIPT"%>
<%
Response.CacheControl = "no-cache"
Response.AddHeader "pragma","no-cache"
Response.Expires = -1
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript" language="javascript">
        function RefreshImage(valImageId) {
            var objImage = document.getElementById(valImageId)
            if (objImage == undefined) {
                return;
            }
            var now = new Date();
            objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
        }
    </script>
</head>
<body>
    <form name="form1" id="form1" method="post">
    <div style="text-align: center; margin-top: 20px;">
        <%
        if Request.ServerVariables("REQUEST_METHOD") = "POST" and IsEmpty(Request.Form("btnRetry")) then
            Dim lblResult, lblColor
            if IsEmpty(Session("ASPCAPTCHA")) or Trim(Session("ASPCAPTCHA")) = "" then
                lblResult = "This test has expired."
                lblColor = "red"
            else
                Dim TestValue : TestValue = Trim(Request.Form("txtCaptcha"))
                '//Uppercase fix for turkish charset//
                TestValue = Replace(TestValue, "i", "I", 1, -1, 1)
                TestValue = Replace(TestValue, "ִ°", "I", 1, -1, 1)
                TestValue = Replace(TestValue, "ִ±", "I", 1, -1, 1)
                '////////////////////
                TestValue = UCase(TestValue)

                if StrComp(TestValue, Trim(Session("ASPCAPTCHA")), 1) = 0 then
                    lblResult = "CAPTCHA PASSED"
                    lblColor = "green"

                else
                    lblResult = "CAPTCHA FAILED"
                    lblColor = "red"
                end if
                '//IMPORTANT: You must remove session value for security after the CAPTCHA test//
                Session("ASPCAPTCHA") = vbNullString
                Session.Contents.Remove("ASPCAPTCHA")
                '////////////////////
            end if
        %>
        <p><span style="color: <%=lblColor%>; font-weight: bold;"><%=lblResult%></span></p>
        <input type="submit" name="btnRetry" id="btnRetry" value="Take another test" />
        <%else%>
        <img src="captcha.asp" id="imgCaptcha" />&nbsp;<a href="javascript:void(0);" onclick="RefreshImage('imgCaptcha');">Get a new challenge</a><br />
        Write the characters in the image above<br />
        <input type="text" name="txtCaptcha" id="txtCaptcha" value="" /><br />
        <input type="submit" name="btnSubmit" id="btnSubmit" value="Submit" />
        <%end if%>
    </div>
    </form>
</body>
</html>

2 个答案:

答案 0 :(得分:0)

可能的解决方案是使用此link

它提供了3个步骤的解决方案

1-将文件复制到您的解决方案

2-添加客户端代码

<!-- #include file ="BotDetect.asp" -->
</head>

[…]

<% ' Adding BotDetect Captcha to the page 
    Dim SampleCaptcha : Set SampleCaptcha = (New Captcha)("SampleCaptcha")
    SampleCaptcha.UserInputID = "CaptchaCode"
    Response.Write SampleCaptcha.Html
%>

<input name="CaptchaCode" id="CaptchaCode" type="text" />

3-添加服务器端代码

<% If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
    Dim isHuman : isHuman = SampleCaptcha.Validate()

    If Not isHuman Then 
        'show error message
    Else 
        'Captcha validation passed
    End If 
End If %>

答案 1 :(得分:0)

我总是使用reCaptcha项目中提供的API - 它们有很好的示例代码,它让我不得不一直重新发明轮子! https://developers.google.com/recaptcha/