如何使用验证码在我的HTML弹出窗口
How to use captcha in my HTML pop up window
我想在我的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" /> <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/
相关文章:
- 窗口大小html css
- 如何关闭html中的iframe弹出窗口
- javascript弹出窗口没有正确加载html表单
- 按下一个HTML按钮,该按钮使用一个功能在同一个新窗口中打开URL
- 从html锚元素传递窗口对象
- 编辑弹出窗口的HTML的单击命令
- Chrome应用程序在全屏中创建新窗口-html元素不是全高的
- 基本html页面和弹出窗口之间的数据交换
- 使用html中的jquery输入值窗口提示
- HTML 框架 - 防止引导弹出窗口在用户单击正文时消失
- HTML窗口弹出窗口和iPad的正确降级
- 在其他html窗口中创建一个html窗口
- HTML窗口刷新页面顶部
- 如何将数据从Parent html窗口传递到弹出窗口
- 传递COM和访问HTML窗口之间的组件
- 如何显示页面上没有地址栏和状态栏的html窗口
- 跨HTML窗口的Javascript函数调用
- 如何从另一个HTML窗口更改1个HTML窗口的背景图像
- Javascript HTML窗口打印问题
- HTML窗口打开按钮单击在IE中不起作用