给Emlog验证码添加点击刷功能

这个功能很不错,转过来和所有使用emlog的童靴分享。

        众所周知EMlog验证码一旦加载了却无法再次只刷新验证码,这样很不爽,偶尔看不清楚却导致必须将整个页面刷新一次才能获取新的验证码,这样严重 影响用户的心情,一个小小的验证码确实能看出EMlog在人性化的一方面还需要改进。实际上一两行代码就可以使博客系统更加人性化,我们何乐而不为呢?废 话不多说,下面结合EMlog讲讲如何点击验证码实现自动刷新验证码的功能。

        核心代码是在img标签中加入:onclick="this.src=this.src+'?'",他的作用就是当点击图片的时候加载验证码。为了 使在鼠标点击验证码图片时有手型链接效果,可以在img标签中加入style="cursor : pointer;",同时还可以加入alt和title属性。

        就EMlog而言,需要修改的验证码有登陆验证、评论验证及碎语验证(手机版除外),所涉及到的文件有:

1.修改/lib/function.login.php

function loginPage()
{
    global $login_code;
    $login_code == 'y' ?
    $ckcode = "<span>验证码</span>
    <div class="val"><input name="imgcode" id="imgcode" type="text" />
    <img 
style="cursor : pointer;" alt="未显示?请点击刷新" title="看不清楚?请点击刷新" onclick="this.src=this.src+'?'"
 
src="../lib/checkcode.php" align="absmiddle"></div>" :
    $ckcode = '';
    require_once(getViews('login'));
    cleanPage();
    exit;
}


2.修改/index.php

//comments
    $cheackimg = $comment_code == 'y' ? "<img 
style="cursor : pointer;" alt="未显示?请点击刷新" title="看不清楚?请点击刷新" onclick="this.src=this.src+'?'"
src="".BLOG_URL."lib/checkcode.php" align="absmiddle" /><input name="imgcode"  type="text" class="input" size="5">" : '';
    $ckname = isset($_COOKIE['commentposter']) ? htmlspecialchars(stripslashes($_COOKIE['commentposter'])) : '';
    $ckmail = isset($_COOKIE['postermail']) ? $_COOKIE['postermail'] : '';
    $ckurl = isset($_COOKIE['posterurl']) ? $_COOKIE['posterurl'] : '';
    $comments = $emComment->getComments(0, $logid, 'n');


3.修改/t/index.php(我的是3.4版,好像没有这个)

4.修改其他用到验证码的地方。比如我添加的友链插件/content/plugins/linklink_show.php

$log_content=$log_content.(verification=='yes'?'<img src="./lib/checkcode.php" align="absmiddle" style="cursor : pointer;" alt="未显示?请点击刷新" title="看不清楚?请点击刷新" onclick="this.src=this.src+'?'" /><input name="imgcode"  type="text" class="input" size="5">':'').'&nbsp<input type="submit" name="" value="申请链接"  /><input type="reset" name="" value="重新填写"  /></form>';//验证码

这里要注意单引号、双引号和转义符的使用。

原理是将上述三文件中验证码img标签中加入:style="cursor : pointer;" alt="未显示?请点击刷新" title="看不清楚?请点击刷新" onclick="this.src=this.src+'?'",即可实现点击验证码刷新功能。

经测试在firefox,ie6,chrome下均未发现异常。大家可以点击刷新本博的验证码试试。

参考链接:http://huikon.cn/post-189.html

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享