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

How to use captcha in my HTML pop up window

本文关键字:HTML 窗口 我的 何使用 验证      更新时间:2023-09-26

我想在我的HTML弹出窗口中使用验证码,我在网上找到了一个简单的验证码,但我如何编写if语句以确保该人在解决验证码之前不能按同意按钮?我如何引用captcha 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>

一个可能的解决方案是使用这个链接。

它提供了一个三步解决方案

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 %>

我一直使用reCaptcha项目提供的api -它们有很好的示例代码,它节省了我重新发明轮子的时间!https://developers.google.com/recaptcha/