网络编程
位置:首页>> 网络编程>> Asp编程>> PJBlog3优化——单击自动输入验证码

PJBlog3优化——单击自动输入验证码

作者:dudo 来源:dudo博客 发布时间:2009-05-17 11:03:00 

标签:pjblog,优化,验证码

从PJBlog 2.7开始,验证码的功能就很好很强大了,但是同时也给手工输入带来了不小的麻烦——经常输错。之前我写了一个《自己写的一个PJBlog中可以双击输入验证码的修改》,不过在那篇文章里用的方法是在页面底部加一个iframe来实现的双击,在PJBlog 3里面已经有了AJAX的功能,所以完全不用那么麻烦了。

一、不用担心失去保护机制

    当然很多人的疑问就是,这样做的话似乎验证码的保护机制就完全失去了意思。其实不然,所有的灌水机都是一段程序代码,由于验证码还是以图片的形式存在,只有点击之后才能获得数字形式,所以灌水机很难轻松模拟这个单击的动作。当然,对于手动的灌水行为无论是哪种验证码保护方式都是避免不了的,除非你限制发表留言的间隔时间。

二、改进步骤:

1、在common/ajax.js的最后面添加如下代码:

 

function get(url,obj1,obj2)   
{   
           
      var xmlhttp = CreateXMLHTTP();   
        if(!xmlhttp)   
      {   
         alert("你的浏览器不支持XMLHTTP!!");   
           return;   
       }   
     xmlhttp.onreadystatechange=requestdata;   
       xmlhttp.open("GET",url,true);   
     xmlhttp.send(null);   
       function requestdata()   
        {   
            
              fopen(obj1);   
              echo(obj1,"<img src='images/loading.gif'>");   
                if(xmlhttp.readyState==4)   
             {   
                 if(xmlhttp.status==200)   
                   {   
                     if(obj1!=obj2){fclose(obj1);};   
                        $(obj2).value = xmlhttp.responseText;   
                        
                  }   
             }   
            
      }   
}

2、在根目录下的Action.asp中找到

If request.QueryString("action") = "checkAlias" then  

替换为

'-------------- [code] -----------------   
If request.QueryString("action") = "code" Then  
  If ChkPost() Then  
     Dim code   
      code = Session("GetCode")   
     Response.Write code   
   End If  
'-------------- [Alias] -----------------   
ElseIf request.QueryString("action") = "checkAlias" then  

3、更改模板文件:在template/static.htm中找到(注:为了排版方便,下面的代码有断行和空格)

<input name="validate" type="text" size="4" class="userpass" maxlength="4"    
onfocus="this.select()"/>  
                  <img id="vcodeImg" src="about:blank" onerror="this.onerror=null;this.src='common/getcode.asp?s='+Math.random();"  
                            alt="验证码" title="看不清楚?点击刷新验证码!" style="margin-right:40px;cursor:pointer;width:40px;height:18px;margin-bottom:-4px;margin-top:3px;"  
                            onclick="src='common/getcode.asp?s='+Math.random()"/>

  替换为

<input id="validate" name="validate" type="text" size="4" class="userpass" maxlength="4"  
 onfocus="this.select()" onclick="get('action.asp?action=code','c','validate')" />    
                   <img id="vcodeImg" src="about:blank"    
                             onerror="this.onerror=null;this.src='common/getcode.asp?s='+Math.random();"  
                            alt="验证码" title="看不清楚?点击刷新验证码!" style="margin-right:40px;cursor:pointer;   
                            width:40px;height:18px;margin-bottom:-4px;margin-top:3px;"   
                            onclick="src='common/getcode.asp?s='+Math.random()"/><span id="c">提示:单击验证码</span>

如果你使用的是动态或者半静态模式,那么你需要在class/cls_article.asp中将上面的代码替换为

<input id="validate" name="validate" type="text" size="4" class="userpass" maxlength="4"  
 onfocus="this.select()" onclick="get('action.asp?action=code','c','validate')" />  
 <%=getcode()%><span id="c">提示:单击验证码</span>

 至此,修改完毕了。如果大家有什么好的意见可以给我留言:)

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com