要ASP的哦,刚看了一些ASPX的,我不知是否能用在ASP里
知道的会的大侠们,帮我写一下,在哪些页面要加什么,如何实现
14 个解决方案
#1
1,下载文件
http://www.blueidea.com/articleimg/2005/08/2671/imgchk.rar (如果此下载连接失效,请联系本人)该压缩包为 imgchk 文件夹 ,其中有三个文件:validatecode.asp,validatebody.fix,validatehead.fix主要即是为生成 验证码 服务的。将解压后得到的 imgchk 文件夹直接释放在需要在某页添加验证码的同目录下(比如 addnew.asp 需要添加验证码,该文件在 cnbruce 文件夹下,则将 imgchk 文件夹同时释放到 cnbruce 文件夹 中)
2,添加显示验证码和输入框 需要添加验证码的页面中添加如下代码:
<input name='validatecode' type='text' size='5'> <img src='imgchk/validatecode.asp' align='absmiddle' border='0'>
说明:具体操作中可以用网页编辑软件打开需要添加验证码的页面,然后在需要显示验证码的位置输入 验证码 这三个汉字(这主要是给别人起一个提示作用,相当于一项内容的标题),然后选中这三个字,点网页编辑软件中的代码,找到反白显示的验证码这三个字,然后将文本光标在它后面点一下,再将上面的这行代码复制粘贴到那里。这时你可以保存后浏览它看看验证码出来没有,要是没出来,就说明你将imgchk 文件夹放错了位置。
3,记录接受页面处理
在步骤2中,一定会将记录提交到某个页面处理(有网友说找不到此页面,其实一般情况下你可以看看与加了验证码的页面在同一目录中的文件,哪个文件名是save或者文件名中包含了save的),那么在该处理页中添加如下代码:
(这部分调用代码是关键,网上关于这个问题的处理方法很多,但不少都是因为这部分代码有问题而引导致记录接受页面浏览时报错!还有,一定要注意这段代码的插入位置,它不是加在任何位置都行的,必须加在此页面的头部,你可以看看,也许你的页面中有许多形式 <%……%>但你一定要将下面的代码放在第一位。)
<%
If Trim(Request.Form("validatecode"))=Empty Or Trim(Session("cnbruce.com_ValidateCode"))<>Trim(Request.Form("validatecode")) Then
response.write"<script>alert('对不起,请输入正确的验证码!');history.back();</Script>"
response.end()
end if
%>
验证码原理:
生成验证码图片的时候,同时生成了一个Session,其值就是验证码图片中的数字值。同时,提供输入框让用户输入,提交输入值后,与已有的Session值进行比较,根据判断结果做相应判断。
http://www.blueidea.com/articleimg/2005/08/2671/imgchk.rar (如果此下载连接失效,请联系本人)该压缩包为 imgchk 文件夹 ,其中有三个文件:validatecode.asp,validatebody.fix,validatehead.fix主要即是为生成 验证码 服务的。将解压后得到的 imgchk 文件夹直接释放在需要在某页添加验证码的同目录下(比如 addnew.asp 需要添加验证码,该文件在 cnbruce 文件夹下,则将 imgchk 文件夹同时释放到 cnbruce 文件夹 中)
2,添加显示验证码和输入框 需要添加验证码的页面中添加如下代码:
<input name='validatecode' type='text' size='5'> <img src='imgchk/validatecode.asp' align='absmiddle' border='0'>
说明:具体操作中可以用网页编辑软件打开需要添加验证码的页面,然后在需要显示验证码的位置输入 验证码 这三个汉字(这主要是给别人起一个提示作用,相当于一项内容的标题),然后选中这三个字,点网页编辑软件中的代码,找到反白显示的验证码这三个字,然后将文本光标在它后面点一下,再将上面的这行代码复制粘贴到那里。这时你可以保存后浏览它看看验证码出来没有,要是没出来,就说明你将imgchk 文件夹放错了位置。
3,记录接受页面处理
在步骤2中,一定会将记录提交到某个页面处理(有网友说找不到此页面,其实一般情况下你可以看看与加了验证码的页面在同一目录中的文件,哪个文件名是save或者文件名中包含了save的),那么在该处理页中添加如下代码:
(这部分调用代码是关键,网上关于这个问题的处理方法很多,但不少都是因为这部分代码有问题而引导致记录接受页面浏览时报错!还有,一定要注意这段代码的插入位置,它不是加在任何位置都行的,必须加在此页面的头部,你可以看看,也许你的页面中有许多形式 <%……%>但你一定要将下面的代码放在第一位。)
<%
If Trim(Request.Form("validatecode"))=Empty Or Trim(Session("cnbruce.com_ValidateCode"))<>Trim(Request.Form("validatecode")) Then
response.write"<script>alert('对不起,请输入正确的验证码!');history.back();</Script>"
response.end()
end if
%>
验证码原理:
生成验证码图片的时候,同时生成了一个Session,其值就是验证码图片中的数字值。同时,提供输入框让用户输入,提交输入值后,与已有的Session值进行比较,根据判断结果做相应判断。
#2
谢谢hongmaohouzi 回复的这么快,我晚上在家时试试,现在单位中没办法试验,试好了来打分
#3
网上很多源码,百度一下!
#4
第3步做不下去了,不知要加哪好了!!!我注册时出现已经注册过的ID时跳到一个页面提示一下,regbad这个,如果都没问题直接就到regok这个了,你说的那些save的没有怎么办!!要建个?
#5
==========================这段代码放在注册的页面==============================
验证码:<input name="CheckCode" type="password" id="CheckCode" size="5" maxlength="20"><img src="checkcode.asp" height="18" alt="验证码,看不清楚?请点击刷新验证码" style="cursor : pointer;" onclick="this.src='checkcode.asp'"> <%
CheckCode = Trim(Request.Form("CheckCode"))
If Request("show") <> "" then
if CheckCode="" then
ErrMsg="验证码不能为空!"
else
if Session("code")="" then
ErrMsg="你留言的时间过长,请重新留言。"
else
if CheckCode<>CStr(Session("code")) then
ErrMsg="您输入的确认码和系统产生的不一致,请重新输入。"
else
Call add() '写入数据库
Response.Redirect "index.asp" '到文章显示的页面
end if
end if
end if
response.Write "<font color=red>" & ErrMsg & "</font>"
End if
%>
验证码:<input name="CheckCode" type="password" id="CheckCode" size="5" maxlength="20"><img src="checkcode.asp" height="18" alt="验证码,看不清楚?请点击刷新验证码" style="cursor : pointer;" onclick="this.src='checkcode.asp'"> <%
CheckCode = Trim(Request.Form("CheckCode"))
If Request("show") <> "" then
if CheckCode="" then
ErrMsg="验证码不能为空!"
else
if Session("code")="" then
ErrMsg="你留言的时间过长,请重新留言。"
else
if CheckCode<>CStr(Session("code")) then
ErrMsg="您输入的确认码和系统产生的不一致,请重新输入。"
else
Call add() '写入数据库
Response.Redirect "index.asp" '到文章显示的页面
end if
end if
end if
response.Write "<font color=red>" & ErrMsg & "</font>"
End if
%>
#6
<%
Const nMaxSaturation = 100 ' 最大色彩饱和度
Const nBlankNoisyDotOdds = 0.2 ' 空白处噪点率
Const nColorNoisyDotOdds = 0.1 ' 有色处噪点率
Const nCharCount = 4 ' 产生的字符个数
Const nPixelWidth = 20 ' 单个字符位图的宽度
Const nPixelHeight = 20 ' 单个字符位图的高度
Const nColorHue = 220 ' 显示验证码的色调(-1表示随机色调, -2表示灰度色调)
Const nAngleRandom = 10 ' 角度随机量
Const nLengthRandom = 10 ' 长度随机量(百分比)
Const cCharSet = "0123456789"
' 构成验证码的字符集
' 如果扩充了下边的字母矢量库,则可以相应扩充这个字符集
Dim Buf(), DigtalStr
Dim Lines(), LineCount
Dim CursorX, CursorY, DirX, DirY
Randomize
Call CreatValidCode("GetCode")
Sub CDGen_Reset()
' 复位矢量笔和环境变量
LineCount = 0
CursorX = 0
CursorY = 0
' 初始的光笔方向是垂直向下
DirX = 0
DirY = 1
End Sub
Sub CDGen_Clear()
' 清空位图阵列
Dim i, j
ReDim Buf(nPixelHeight - 1, nCharCount * nPixelWidth - 1)
For j = 0 To nPixelHeight - 1
For i = 0 To nCharCount * nPixelWidth - 1
Buf(j, i) = 0
Next
Next
End Sub
Const nMaxSaturation = 100 ' 最大色彩饱和度
Const nBlankNoisyDotOdds = 0.2 ' 空白处噪点率
Const nColorNoisyDotOdds = 0.1 ' 有色处噪点率
Const nCharCount = 4 ' 产生的字符个数
Const nPixelWidth = 20 ' 单个字符位图的宽度
Const nPixelHeight = 20 ' 单个字符位图的高度
Const nColorHue = 220 ' 显示验证码的色调(-1表示随机色调, -2表示灰度色调)
Const nAngleRandom = 10 ' 角度随机量
Const nLengthRandom = 10 ' 长度随机量(百分比)
Const cCharSet = "0123456789"
' 构成验证码的字符集
' 如果扩充了下边的字母矢量库,则可以相应扩充这个字符集
Dim Buf(), DigtalStr
Dim Lines(), LineCount
Dim CursorX, CursorY, DirX, DirY
Randomize
Call CreatValidCode("GetCode")
Sub CDGen_Reset()
' 复位矢量笔和环境变量
LineCount = 0
CursorX = 0
CursorY = 0
' 初始的光笔方向是垂直向下
DirX = 0
DirY = 1
End Sub
Sub CDGen_Clear()
' 清空位图阵列
Dim i, j
ReDim Buf(nPixelHeight - 1, nCharCount * nPixelWidth - 1)
For j = 0 To nPixelHeight - 1
For i = 0 To nCharCount * nPixelWidth - 1
Buf(j, i) = 0
Next
Next
End Sub
#7
Sub CDGen_PSet(X, Y)
' 在位图阵列上画点
Buf(Y, X) = 1
End Sub
Sub CDGen_Line(X1, Y1, X2, Y2)
' 在位图阵列上画线
Dim DX, DY, DeltaT, i
DX = X2 - X1
DY = Y2 - Y1
If Abs(DX) > Abs(DY) Then DeltaT = Abs(DX) Else DeltaT = Abs(DY)
For i = 0 To DeltaT
CDGen_PSet X1 + DX * i / DeltaT, Y1 + DY * i / DeltaT
Next
End Sub
Sub CDGen_FowardDraw(nLength)
' 按当前光笔方向绘制指定长度并移动光笔,正数表示从左向右/从上向下绘制,负数表示从右向左/从下向上绘制
nLength = Sgn(nLength) * Abs(nLength) * (1 - nLengthRandom / 100 + Rnd * nLenghtRandom * 2 / 100)
ReDim Preserve Lines(3, LineCount)
Lines(0, LineCount) = CursorX
Lines(1, LineCount) = CursorY
CursorX = CursorX + DirX * nLength
CursorY = CursorY + DirY * nLength
Lines(2, LineCount) = CursorX
Lines(3, LineCount) = CursorY
LineCount = LineCount + 1
End Sub
Sub CDGen_SetDirection(nAngle)
' 按指定角度设定画笔方向, 正数表示相对当前方向顺时针改变方向,负数表示相对当前方向逆时针改变方向
Dim DX, DY
nAngle = Sgn(nAngle) * (Abs(nAngle) - nAngleRandom + Rnd * nAngleRandom * 2) / 180 * 3.1415926
DX = DirX
DY = DirY
DirX = DX * Cos(nAngle) - DY * Sin(nAngle)
DirY = DX * Sin(nAngle) + DY * Cos(nAngle)
End Sub
Sub CDGen_MoveToMiddle(nActionIndex, nPercent)
' 将画笔光标移动到指定动作的中间点上,nPercent为中间位置的百分比
Dim DeltaX, DeltaY
DeltaX = Lines(2, nActionIndex) - Lines(0, nActionIndex)
DeltaY = Lines(3, nActionIndex) - Lines(1, nActionIndex)
CursorX = Lines(0, nActionIndex) + Sgn(DeltaX) * Abs(DeltaX) * nPercent / 100
CursorY = Lines(1, nActionIndex) + Sgn(DeltaY) * Abs(DeltaY) * nPercent / 100
End Sub
Sub CDGen_MoveCursor(nActionIndex)
' 将画笔光标移动到指定动作的起始点上
CursorX = Lines(0, nActionIndex)
CursorY = Lines(1, nActionIndex)
End Sub
Sub CDGen_Close(nActionIndex)
' 将当前光笔位置与指定动作的起始点闭合并移动光笔
ReDim Preserve Lines(3, LineCount)
Lines(0, LineCount) = CursorX
Lines(1, LineCount) = CursorY
CursorX = Lines(0, nActionIndex)
CursorY = Lines(1, nActionIndex)
Lines(2, LineCount) = CursorX
Lines(3, LineCount) = CursorY
LineCount = LineCount + 1
End Sub
Sub CDGen_CloseToMiddle(nActionIndex, nPercent)
' 将当前光笔位置与指定动作的中间点闭合并移动光笔,nPercent为中间位置的百分比
Dim DeltaX, DeltaY
ReDim Preserve Lines(3, LineCount)
Lines(0, LineCount) = CursorX
Lines(1, LineCount) = CursorY
DeltaX = Lines(2, nActionIndex) - Lines(0, nActionIndex)
DeltaY = Lines(3, nActionIndex) - Lines(1, nActionIndex)
CursorX = Lines(0, nActionIndex) + Sgn(DeltaX) * Abs(DeltaX) * nPercent / 100
CursorY = Lines(1, nActionIndex) + Sgn(DeltaY) * Abs(DeltaY) * nPercent / 100
Lines(2, LineCount) = CursorX
Lines(3, LineCount) = CursorY
LineCount = LineCount + 1
End Sub
' 在位图阵列上画点
Buf(Y, X) = 1
End Sub
Sub CDGen_Line(X1, Y1, X2, Y2)
' 在位图阵列上画线
Dim DX, DY, DeltaT, i
DX = X2 - X1
DY = Y2 - Y1
If Abs(DX) > Abs(DY) Then DeltaT = Abs(DX) Else DeltaT = Abs(DY)
For i = 0 To DeltaT
CDGen_PSet X1 + DX * i / DeltaT, Y1 + DY * i / DeltaT
Next
End Sub
Sub CDGen_FowardDraw(nLength)
' 按当前光笔方向绘制指定长度并移动光笔,正数表示从左向右/从上向下绘制,负数表示从右向左/从下向上绘制
nLength = Sgn(nLength) * Abs(nLength) * (1 - nLengthRandom / 100 + Rnd * nLenghtRandom * 2 / 100)
ReDim Preserve Lines(3, LineCount)
Lines(0, LineCount) = CursorX
Lines(1, LineCount) = CursorY
CursorX = CursorX + DirX * nLength
CursorY = CursorY + DirY * nLength
Lines(2, LineCount) = CursorX
Lines(3, LineCount) = CursorY
LineCount = LineCount + 1
End Sub
Sub CDGen_SetDirection(nAngle)
' 按指定角度设定画笔方向, 正数表示相对当前方向顺时针改变方向,负数表示相对当前方向逆时针改变方向
Dim DX, DY
nAngle = Sgn(nAngle) * (Abs(nAngle) - nAngleRandom + Rnd * nAngleRandom * 2) / 180 * 3.1415926
DX = DirX
DY = DirY
DirX = DX * Cos(nAngle) - DY * Sin(nAngle)
DirY = DX * Sin(nAngle) + DY * Cos(nAngle)
End Sub
Sub CDGen_MoveToMiddle(nActionIndex, nPercent)
' 将画笔光标移动到指定动作的中间点上,nPercent为中间位置的百分比
Dim DeltaX, DeltaY
DeltaX = Lines(2, nActionIndex) - Lines(0, nActionIndex)
DeltaY = Lines(3, nActionIndex) - Lines(1, nActionIndex)
CursorX = Lines(0, nActionIndex) + Sgn(DeltaX) * Abs(DeltaX) * nPercent / 100
CursorY = Lines(1, nActionIndex) + Sgn(DeltaY) * Abs(DeltaY) * nPercent / 100
End Sub
Sub CDGen_MoveCursor(nActionIndex)
' 将画笔光标移动到指定动作的起始点上
CursorX = Lines(0, nActionIndex)
CursorY = Lines(1, nActionIndex)
End Sub
Sub CDGen_Close(nActionIndex)
' 将当前光笔位置与指定动作的起始点闭合并移动光笔
ReDim Preserve Lines(3, LineCount)
Lines(0, LineCount) = CursorX
Lines(1, LineCount) = CursorY
CursorX = Lines(0, nActionIndex)
CursorY = Lines(1, nActionIndex)
Lines(2, LineCount) = CursorX
Lines(3, LineCount) = CursorY
LineCount = LineCount + 1
End Sub
Sub CDGen_CloseToMiddle(nActionIndex, nPercent)
' 将当前光笔位置与指定动作的中间点闭合并移动光笔,nPercent为中间位置的百分比
Dim DeltaX, DeltaY
ReDim Preserve Lines(3, LineCount)
Lines(0, LineCount) = CursorX
Lines(1, LineCount) = CursorY
DeltaX = Lines(2, nActionIndex) - Lines(0, nActionIndex)
DeltaY = Lines(3, nActionIndex) - Lines(1, nActionIndex)
CursorX = Lines(0, nActionIndex) + Sgn(DeltaX) * Abs(DeltaX) * nPercent / 100
CursorY = Lines(1, nActionIndex) + Sgn(DeltaY) * Abs(DeltaY) * nPercent / 100
Lines(2, LineCount) = CursorX
Lines(3, LineCount) = CursorY
LineCount = LineCount + 1
End Sub
#8
pursuetime 大侠,你刚贴的这些是不是全放注册页面里呀,怎么也不行呀
#9
将压缩包放,解压缩后,放到指定的目录下,如果路径不正确,显示不出来验证码,可以修改这里<img src='imgchk/validatecode.asp' ...>
下面是一个小例子:
login.asp登录页面代码:
<html>
<body>
<form name=form1 action=save.asp method="post">
验证码:<input name=validatecode type='text' size='5'> <img src='imgchk/validatecode.asp' align='absmiddle' border='0'><br>
<input name=submit type=submit>
</form>
</body>
</html>
save.asp页面代码,接收验证码的页面
<%
'验证码输入不正确:
If Trim(Request("validatecode"))=Empty or Trim(Session("ValidateCode"))<>Trim(Request("validatecode")) Then
response.write("请输入正确的验证码")
response.write(Request("validatecode"))
response.write("#####")
response.write(Session("ValidateCode"))
response.end
else
'验证码输入正确:
response.write("验证码输入正确!")
response.write(Request("validatecode"))
response.write("#####")
response.write(Session("ValidateCode"))
response.end
end if
%>
这只是一个小例子,你根据你的具体页面来进行改造一下就可以了!
下面是一个小例子:
login.asp登录页面代码:
<html>
<body>
<form name=form1 action=save.asp method="post">
验证码:<input name=validatecode type='text' size='5'> <img src='imgchk/validatecode.asp' align='absmiddle' border='0'><br>
<input name=submit type=submit>
</form>
</body>
</html>
save.asp页面代码,接收验证码的页面
<%
'验证码输入不正确:
If Trim(Request("validatecode"))=Empty or Trim(Session("ValidateCode"))<>Trim(Request("validatecode")) Then
response.write("请输入正确的验证码")
response.write(Request("validatecode"))
response.write("#####")
response.write(Session("ValidateCode"))
response.end
else
'验证码输入正确:
response.write("验证码输入正确!")
response.write(Request("validatecode"))
response.write("#####")
response.write(Session("ValidateCode"))
response.end
end if
%>
这只是一个小例子,你根据你的具体页面来进行改造一下就可以了!
#10
请问如果是想在一个页面处理这些验证该怎么办呢?不想跳转到其他页面验证,我的意思是判断代码就在本页就处理了。
#11
==========================这段代码放在注册的页面==============================
验证码: <input name="CheckCode" type="password" id="CheckCode" size="5" maxlength="20"> <img src="checkcode.asp" height="18" alt="验证码,看不清楚?请点击刷新验证码" style="cursor : pointer;" onclick="this.src='checkcode.asp'"> <%
CheckCode = Trim(Request.Form("CheckCode"))
If Request("show") <> "" then
if CheckCode="" then
ErrMsg="验证码不能为空!"
else
if Session("code")="" then
ErrMsg="你留言的时间过长,请重新留言。"
else
if CheckCode <>CStr(Session("code")) then
ErrMsg="您输入的确认码和系统产生的不一致,请重新输入。"
else
Call add() '写入数据库
Response.Redirect "index.asp" '到文章显示的页面
end if
end if
end if
response.Write " <font color=red>" & ErrMsg & " </font>"
End if
%>
===========================我csdn博客里=====================================
checkcode.asp 这是一个页面
验证码: <input name="CheckCode" type="password" id="CheckCode" size="5" maxlength="20"> <img src="checkcode.asp" height="18" alt="验证码,看不清楚?请点击刷新验证码" style="cursor : pointer;" onclick="this.src='checkcode.asp'"> <%
CheckCode = Trim(Request.Form("CheckCode"))
If Request("show") <> "" then
if CheckCode="" then
ErrMsg="验证码不能为空!"
else
if Session("code")="" then
ErrMsg="你留言的时间过长,请重新留言。"
else
if CheckCode <>CStr(Session("code")) then
ErrMsg="您输入的确认码和系统产生的不一致,请重新输入。"
else
Call add() '写入数据库
Response.Redirect "index.asp" '到文章显示的页面
end if
end if
end if
response.Write " <font color=red>" & ErrMsg & " </font>"
End if
%>
===========================我csdn博客里=====================================
checkcode.asp 这是一个页面
#12
各位有没有汉字的验证码了?
#13
安你上面写的步骤做。做好一测试还没等我进入留言页面就提示不正确的验证码。这让我很不理解。请指导一下!
#1
1,下载文件
http://www.blueidea.com/articleimg/2005/08/2671/imgchk.rar (如果此下载连接失效,请联系本人)该压缩包为 imgchk 文件夹 ,其中有三个文件:validatecode.asp,validatebody.fix,validatehead.fix主要即是为生成 验证码 服务的。将解压后得到的 imgchk 文件夹直接释放在需要在某页添加验证码的同目录下(比如 addnew.asp 需要添加验证码,该文件在 cnbruce 文件夹下,则将 imgchk 文件夹同时释放到 cnbruce 文件夹 中)
2,添加显示验证码和输入框 需要添加验证码的页面中添加如下代码:
<input name='validatecode' type='text' size='5'> <img src='imgchk/validatecode.asp' align='absmiddle' border='0'>
说明:具体操作中可以用网页编辑软件打开需要添加验证码的页面,然后在需要显示验证码的位置输入 验证码 这三个汉字(这主要是给别人起一个提示作用,相当于一项内容的标题),然后选中这三个字,点网页编辑软件中的代码,找到反白显示的验证码这三个字,然后将文本光标在它后面点一下,再将上面的这行代码复制粘贴到那里。这时你可以保存后浏览它看看验证码出来没有,要是没出来,就说明你将imgchk 文件夹放错了位置。
3,记录接受页面处理
在步骤2中,一定会将记录提交到某个页面处理(有网友说找不到此页面,其实一般情况下你可以看看与加了验证码的页面在同一目录中的文件,哪个文件名是save或者文件名中包含了save的),那么在该处理页中添加如下代码:
(这部分调用代码是关键,网上关于这个问题的处理方法很多,但不少都是因为这部分代码有问题而引导致记录接受页面浏览时报错!还有,一定要注意这段代码的插入位置,它不是加在任何位置都行的,必须加在此页面的头部,你可以看看,也许你的页面中有许多形式 <%……%>但你一定要将下面的代码放在第一位。)
<%
If Trim(Request.Form("validatecode"))=Empty Or Trim(Session("cnbruce.com_ValidateCode"))<>Trim(Request.Form("validatecode")) Then
response.write"<script>alert('对不起,请输入正确的验证码!');history.back();</Script>"
response.end()
end if
%>
验证码原理:
生成验证码图片的时候,同时生成了一个Session,其值就是验证码图片中的数字值。同时,提供输入框让用户输入,提交输入值后,与已有的Session值进行比较,根据判断结果做相应判断。
http://www.blueidea.com/articleimg/2005/08/2671/imgchk.rar (如果此下载连接失效,请联系本人)该压缩包为 imgchk 文件夹 ,其中有三个文件:validatecode.asp,validatebody.fix,validatehead.fix主要即是为生成 验证码 服务的。将解压后得到的 imgchk 文件夹直接释放在需要在某页添加验证码的同目录下(比如 addnew.asp 需要添加验证码,该文件在 cnbruce 文件夹下,则将 imgchk 文件夹同时释放到 cnbruce 文件夹 中)
2,添加显示验证码和输入框 需要添加验证码的页面中添加如下代码:
<input name='validatecode' type='text' size='5'> <img src='imgchk/validatecode.asp' align='absmiddle' border='0'>
说明:具体操作中可以用网页编辑软件打开需要添加验证码的页面,然后在需要显示验证码的位置输入 验证码 这三个汉字(这主要是给别人起一个提示作用,相当于一项内容的标题),然后选中这三个字,点网页编辑软件中的代码,找到反白显示的验证码这三个字,然后将文本光标在它后面点一下,再将上面的这行代码复制粘贴到那里。这时你可以保存后浏览它看看验证码出来没有,要是没出来,就说明你将imgchk 文件夹放错了位置。
3,记录接受页面处理
在步骤2中,一定会将记录提交到某个页面处理(有网友说找不到此页面,其实一般情况下你可以看看与加了验证码的页面在同一目录中的文件,哪个文件名是save或者文件名中包含了save的),那么在该处理页中添加如下代码:
(这部分调用代码是关键,网上关于这个问题的处理方法很多,但不少都是因为这部分代码有问题而引导致记录接受页面浏览时报错!还有,一定要注意这段代码的插入位置,它不是加在任何位置都行的,必须加在此页面的头部,你可以看看,也许你的页面中有许多形式 <%……%>但你一定要将下面的代码放在第一位。)
<%
If Trim(Request.Form("validatecode"))=Empty Or Trim(Session("cnbruce.com_ValidateCode"))<>Trim(Request.Form("validatecode")) Then
response.write"<script>alert('对不起,请输入正确的验证码!');history.back();</Script>"
response.end()
end if
%>
验证码原理:
生成验证码图片的时候,同时生成了一个Session,其值就是验证码图片中的数字值。同时,提供输入框让用户输入,提交输入值后,与已有的Session值进行比较,根据判断结果做相应判断。
#2
谢谢hongmaohouzi 回复的这么快,我晚上在家时试试,现在单位中没办法试验,试好了来打分
#3
网上很多源码,百度一下!
#4
第3步做不下去了,不知要加哪好了!!!我注册时出现已经注册过的ID时跳到一个页面提示一下,regbad这个,如果都没问题直接就到regok这个了,你说的那些save的没有怎么办!!要建个?
#5
==========================这段代码放在注册的页面==============================
验证码:<input name="CheckCode" type="password" id="CheckCode" size="5" maxlength="20"><img src="checkcode.asp" height="18" alt="验证码,看不清楚?请点击刷新验证码" style="cursor : pointer;" onclick="this.src='checkcode.asp'"> <%
CheckCode = Trim(Request.Form("CheckCode"))
If Request("show") <> "" then
if CheckCode="" then
ErrMsg="验证码不能为空!"
else
if Session("code")="" then
ErrMsg="你留言的时间过长,请重新留言。"
else
if CheckCode<>CStr(Session("code")) then
ErrMsg="您输入的确认码和系统产生的不一致,请重新输入。"
else
Call add() '写入数据库
Response.Redirect "index.asp" '到文章显示的页面
end if
end if
end if
response.Write "<font color=red>" & ErrMsg & "</font>"
End if
%>
验证码:<input name="CheckCode" type="password" id="CheckCode" size="5" maxlength="20"><img src="checkcode.asp" height="18" alt="验证码,看不清楚?请点击刷新验证码" style="cursor : pointer;" onclick="this.src='checkcode.asp'"> <%
CheckCode = Trim(Request.Form("CheckCode"))
If Request("show") <> "" then
if CheckCode="" then
ErrMsg="验证码不能为空!"
else
if Session("code")="" then
ErrMsg="你留言的时间过长,请重新留言。"
else
if CheckCode<>CStr(Session("code")) then
ErrMsg="您输入的确认码和系统产生的不一致,请重新输入。"
else
Call add() '写入数据库
Response.Redirect "index.asp" '到文章显示的页面
end if
end if
end if
response.Write "<font color=red>" & ErrMsg & "</font>"
End if
%>
#6
<%
Const nMaxSaturation = 100 ' 最大色彩饱和度
Const nBlankNoisyDotOdds = 0.2 ' 空白处噪点率
Const nColorNoisyDotOdds = 0.1 ' 有色处噪点率
Const nCharCount = 4 ' 产生的字符个数
Const nPixelWidth = 20 ' 单个字符位图的宽度
Const nPixelHeight = 20 ' 单个字符位图的高度
Const nColorHue = 220 ' 显示验证码的色调(-1表示随机色调, -2表示灰度色调)
Const nAngleRandom = 10 ' 角度随机量
Const nLengthRandom = 10 ' 长度随机量(百分比)
Const cCharSet = "0123456789"
' 构成验证码的字符集
' 如果扩充了下边的字母矢量库,则可以相应扩充这个字符集
Dim Buf(), DigtalStr
Dim Lines(), LineCount
Dim CursorX, CursorY, DirX, DirY
Randomize
Call CreatValidCode("GetCode")
Sub CDGen_Reset()
' 复位矢量笔和环境变量
LineCount = 0
CursorX = 0
CursorY = 0
' 初始的光笔方向是垂直向下
DirX = 0
DirY = 1
End Sub
Sub CDGen_Clear()
' 清空位图阵列
Dim i, j
ReDim Buf(nPixelHeight - 1, nCharCount * nPixelWidth - 1)
For j = 0 To nPixelHeight - 1
For i = 0 To nCharCount * nPixelWidth - 1
Buf(j, i) = 0
Next
Next
End Sub
Const nMaxSaturation = 100 ' 最大色彩饱和度
Const nBlankNoisyDotOdds = 0.2 ' 空白处噪点率
Const nColorNoisyDotOdds = 0.1 ' 有色处噪点率
Const nCharCount = 4 ' 产生的字符个数
Const nPixelWidth = 20 ' 单个字符位图的宽度
Const nPixelHeight = 20 ' 单个字符位图的高度
Const nColorHue = 220 ' 显示验证码的色调(-1表示随机色调, -2表示灰度色调)
Const nAngleRandom = 10 ' 角度随机量
Const nLengthRandom = 10 ' 长度随机量(百分比)
Const cCharSet = "0123456789"
' 构成验证码的字符集
' 如果扩充了下边的字母矢量库,则可以相应扩充这个字符集
Dim Buf(), DigtalStr
Dim Lines(), LineCount
Dim CursorX, CursorY, DirX, DirY
Randomize
Call CreatValidCode("GetCode")
Sub CDGen_Reset()
' 复位矢量笔和环境变量
LineCount = 0
CursorX = 0
CursorY = 0
' 初始的光笔方向是垂直向下
DirX = 0
DirY = 1
End Sub
Sub CDGen_Clear()
' 清空位图阵列
Dim i, j
ReDim Buf(nPixelHeight - 1, nCharCount * nPixelWidth - 1)
For j = 0 To nPixelHeight - 1
For i = 0 To nCharCount * nPixelWidth - 1
Buf(j, i) = 0
Next
Next
End Sub
#7
Sub CDGen_PSet(X, Y)
' 在位图阵列上画点
Buf(Y, X) = 1
End Sub
Sub CDGen_Line(X1, Y1, X2, Y2)
' 在位图阵列上画线
Dim DX, DY, DeltaT, i
DX = X2 - X1
DY = Y2 - Y1
If Abs(DX) > Abs(DY) Then DeltaT = Abs(DX) Else DeltaT = Abs(DY)
For i = 0 To DeltaT
CDGen_PSet X1 + DX * i / DeltaT, Y1 + DY * i / DeltaT
Next
End Sub
Sub CDGen_FowardDraw(nLength)
' 按当前光笔方向绘制指定长度并移动光笔,正数表示从左向右/从上向下绘制,负数表示从右向左/从下向上绘制
nLength = Sgn(nLength) * Abs(nLength) * (1 - nLengthRandom / 100 + Rnd * nLenghtRandom * 2 / 100)
ReDim Preserve Lines(3, LineCount)
Lines(0, LineCount) = CursorX
Lines(1, LineCount) = CursorY
CursorX = CursorX + DirX * nLength
CursorY = CursorY + DirY * nLength
Lines(2, LineCount) = CursorX
Lines(3, LineCount) = CursorY
LineCount = LineCount + 1
End Sub
Sub CDGen_SetDirection(nAngle)
' 按指定角度设定画笔方向, 正数表示相对当前方向顺时针改变方向,负数表示相对当前方向逆时针改变方向
Dim DX, DY
nAngle = Sgn(nAngle) * (Abs(nAngle) - nAngleRandom + Rnd * nAngleRandom * 2) / 180 * 3.1415926
DX = DirX
DY = DirY
DirX = DX * Cos(nAngle) - DY * Sin(nAngle)
DirY = DX * Sin(nAngle) + DY * Cos(nAngle)
End Sub
Sub CDGen_MoveToMiddle(nActionIndex, nPercent)
' 将画笔光标移动到指定动作的中间点上,nPercent为中间位置的百分比
Dim DeltaX, DeltaY
DeltaX = Lines(2, nActionIndex) - Lines(0, nActionIndex)
DeltaY = Lines(3, nActionIndex) - Lines(1, nActionIndex)
CursorX = Lines(0, nActionIndex) + Sgn(DeltaX) * Abs(DeltaX) * nPercent / 100
CursorY = Lines(1, nActionIndex) + Sgn(DeltaY) * Abs(DeltaY) * nPercent / 100
End Sub
Sub CDGen_MoveCursor(nActionIndex)
' 将画笔光标移动到指定动作的起始点上
CursorX = Lines(0, nActionIndex)
CursorY = Lines(1, nActionIndex)
End Sub
Sub CDGen_Close(nActionIndex)
' 将当前光笔位置与指定动作的起始点闭合并移动光笔
ReDim Preserve Lines(3, LineCount)
Lines(0, LineCount) = CursorX
Lines(1, LineCount) = CursorY
CursorX = Lines(0, nActionIndex)
CursorY = Lines(1, nActionIndex)
Lines(2, LineCount) = CursorX
Lines(3, LineCount) = CursorY
LineCount = LineCount + 1
End Sub
Sub CDGen_CloseToMiddle(nActionIndex, nPercent)
' 将当前光笔位置与指定动作的中间点闭合并移动光笔,nPercent为中间位置的百分比
Dim DeltaX, DeltaY
ReDim Preserve Lines(3, LineCount)
Lines(0, LineCount) = CursorX
Lines(1, LineCount) = CursorY
DeltaX = Lines(2, nActionIndex) - Lines(0, nActionIndex)
DeltaY = Lines(3, nActionIndex) - Lines(1, nActionIndex)
CursorX = Lines(0, nActionIndex) + Sgn(DeltaX) * Abs(DeltaX) * nPercent / 100
CursorY = Lines(1, nActionIndex) + Sgn(DeltaY) * Abs(DeltaY) * nPercent / 100
Lines(2, LineCount) = CursorX
Lines(3, LineCount) = CursorY
LineCount = LineCount + 1
End Sub
' 在位图阵列上画点
Buf(Y, X) = 1
End Sub
Sub CDGen_Line(X1, Y1, X2, Y2)
' 在位图阵列上画线
Dim DX, DY, DeltaT, i
DX = X2 - X1
DY = Y2 - Y1
If Abs(DX) > Abs(DY) Then DeltaT = Abs(DX) Else DeltaT = Abs(DY)
For i = 0 To DeltaT
CDGen_PSet X1 + DX * i / DeltaT, Y1 + DY * i / DeltaT
Next
End Sub
Sub CDGen_FowardDraw(nLength)
' 按当前光笔方向绘制指定长度并移动光笔,正数表示从左向右/从上向下绘制,负数表示从右向左/从下向上绘制
nLength = Sgn(nLength) * Abs(nLength) * (1 - nLengthRandom / 100 + Rnd * nLenghtRandom * 2 / 100)
ReDim Preserve Lines(3, LineCount)
Lines(0, LineCount) = CursorX
Lines(1, LineCount) = CursorY
CursorX = CursorX + DirX * nLength
CursorY = CursorY + DirY * nLength
Lines(2, LineCount) = CursorX
Lines(3, LineCount) = CursorY
LineCount = LineCount + 1
End Sub
Sub CDGen_SetDirection(nAngle)
' 按指定角度设定画笔方向, 正数表示相对当前方向顺时针改变方向,负数表示相对当前方向逆时针改变方向
Dim DX, DY
nAngle = Sgn(nAngle) * (Abs(nAngle) - nAngleRandom + Rnd * nAngleRandom * 2) / 180 * 3.1415926
DX = DirX
DY = DirY
DirX = DX * Cos(nAngle) - DY * Sin(nAngle)
DirY = DX * Sin(nAngle) + DY * Cos(nAngle)
End Sub
Sub CDGen_MoveToMiddle(nActionIndex, nPercent)
' 将画笔光标移动到指定动作的中间点上,nPercent为中间位置的百分比
Dim DeltaX, DeltaY
DeltaX = Lines(2, nActionIndex) - Lines(0, nActionIndex)
DeltaY = Lines(3, nActionIndex) - Lines(1, nActionIndex)
CursorX = Lines(0, nActionIndex) + Sgn(DeltaX) * Abs(DeltaX) * nPercent / 100
CursorY = Lines(1, nActionIndex) + Sgn(DeltaY) * Abs(DeltaY) * nPercent / 100
End Sub
Sub CDGen_MoveCursor(nActionIndex)
' 将画笔光标移动到指定动作的起始点上
CursorX = Lines(0, nActionIndex)
CursorY = Lines(1, nActionIndex)
End Sub
Sub CDGen_Close(nActionIndex)
' 将当前光笔位置与指定动作的起始点闭合并移动光笔
ReDim Preserve Lines(3, LineCount)
Lines(0, LineCount) = CursorX
Lines(1, LineCount) = CursorY
CursorX = Lines(0, nActionIndex)
CursorY = Lines(1, nActionIndex)
Lines(2, LineCount) = CursorX
Lines(3, LineCount) = CursorY
LineCount = LineCount + 1
End Sub
Sub CDGen_CloseToMiddle(nActionIndex, nPercent)
' 将当前光笔位置与指定动作的中间点闭合并移动光笔,nPercent为中间位置的百分比
Dim DeltaX, DeltaY
ReDim Preserve Lines(3, LineCount)
Lines(0, LineCount) = CursorX
Lines(1, LineCount) = CursorY
DeltaX = Lines(2, nActionIndex) - Lines(0, nActionIndex)
DeltaY = Lines(3, nActionIndex) - Lines(1, nActionIndex)
CursorX = Lines(0, nActionIndex) + Sgn(DeltaX) * Abs(DeltaX) * nPercent / 100
CursorY = Lines(1, nActionIndex) + Sgn(DeltaY) * Abs(DeltaY) * nPercent / 100
Lines(2, LineCount) = CursorX
Lines(3, LineCount) = CursorY
LineCount = LineCount + 1
End Sub
#8
pursuetime 大侠,你刚贴的这些是不是全放注册页面里呀,怎么也不行呀
#9
将压缩包放,解压缩后,放到指定的目录下,如果路径不正确,显示不出来验证码,可以修改这里<img src='imgchk/validatecode.asp' ...>
下面是一个小例子:
login.asp登录页面代码:
<html>
<body>
<form name=form1 action=save.asp method="post">
验证码:<input name=validatecode type='text' size='5'> <img src='imgchk/validatecode.asp' align='absmiddle' border='0'><br>
<input name=submit type=submit>
</form>
</body>
</html>
save.asp页面代码,接收验证码的页面
<%
'验证码输入不正确:
If Trim(Request("validatecode"))=Empty or Trim(Session("ValidateCode"))<>Trim(Request("validatecode")) Then
response.write("请输入正确的验证码")
response.write(Request("validatecode"))
response.write("#####")
response.write(Session("ValidateCode"))
response.end
else
'验证码输入正确:
response.write("验证码输入正确!")
response.write(Request("validatecode"))
response.write("#####")
response.write(Session("ValidateCode"))
response.end
end if
%>
这只是一个小例子,你根据你的具体页面来进行改造一下就可以了!
下面是一个小例子:
login.asp登录页面代码:
<html>
<body>
<form name=form1 action=save.asp method="post">
验证码:<input name=validatecode type='text' size='5'> <img src='imgchk/validatecode.asp' align='absmiddle' border='0'><br>
<input name=submit type=submit>
</form>
</body>
</html>
save.asp页面代码,接收验证码的页面
<%
'验证码输入不正确:
If Trim(Request("validatecode"))=Empty or Trim(Session("ValidateCode"))<>Trim(Request("validatecode")) Then
response.write("请输入正确的验证码")
response.write(Request("validatecode"))
response.write("#####")
response.write(Session("ValidateCode"))
response.end
else
'验证码输入正确:
response.write("验证码输入正确!")
response.write(Request("validatecode"))
response.write("#####")
response.write(Session("ValidateCode"))
response.end
end if
%>
这只是一个小例子,你根据你的具体页面来进行改造一下就可以了!
#10
请问如果是想在一个页面处理这些验证该怎么办呢?不想跳转到其他页面验证,我的意思是判断代码就在本页就处理了。
#11
==========================这段代码放在注册的页面==============================
验证码: <input name="CheckCode" type="password" id="CheckCode" size="5" maxlength="20"> <img src="checkcode.asp" height="18" alt="验证码,看不清楚?请点击刷新验证码" style="cursor : pointer;" onclick="this.src='checkcode.asp'"> <%
CheckCode = Trim(Request.Form("CheckCode"))
If Request("show") <> "" then
if CheckCode="" then
ErrMsg="验证码不能为空!"
else
if Session("code")="" then
ErrMsg="你留言的时间过长,请重新留言。"
else
if CheckCode <>CStr(Session("code")) then
ErrMsg="您输入的确认码和系统产生的不一致,请重新输入。"
else
Call add() '写入数据库
Response.Redirect "index.asp" '到文章显示的页面
end if
end if
end if
response.Write " <font color=red>" & ErrMsg & " </font>"
End if
%>
===========================我csdn博客里=====================================
checkcode.asp 这是一个页面
验证码: <input name="CheckCode" type="password" id="CheckCode" size="5" maxlength="20"> <img src="checkcode.asp" height="18" alt="验证码,看不清楚?请点击刷新验证码" style="cursor : pointer;" onclick="this.src='checkcode.asp'"> <%
CheckCode = Trim(Request.Form("CheckCode"))
If Request("show") <> "" then
if CheckCode="" then
ErrMsg="验证码不能为空!"
else
if Session("code")="" then
ErrMsg="你留言的时间过长,请重新留言。"
else
if CheckCode <>CStr(Session("code")) then
ErrMsg="您输入的确认码和系统产生的不一致,请重新输入。"
else
Call add() '写入数据库
Response.Redirect "index.asp" '到文章显示的页面
end if
end if
end if
response.Write " <font color=red>" & ErrMsg & " </font>"
End if
%>
===========================我csdn博客里=====================================
checkcode.asp 这是一个页面
#12
各位有没有汉字的验证码了?
#13
安你上面写的步骤做。做好一测试还没等我进入留言页面就提示不正确的验证码。这让我很不理解。请指导一下!