webstermobile
Fork me on GitHub
个人博客

ECshop中验证码的使用

ECshop中验证码的调用

<input type="text" size="8" name="captcha" class="inputBg" />
<img src="captcha.php?{$rand}" alt="captcha" onClick="this.src='captcha.php?'+Math.random()" class="captcha">

验证码的验证

if (empty($_POST['captcha']))
    {
     show_message($_LANG['order']['captcha_empty']);
    }

   
    include_once('includes/cls_captcha.php');

    $validator = new captcha();
    //$validator->session_word = 'captcha_login';
    if (!$validator->check_word(($_POST['captcha'])))
    {
        show_message($_LANG['invalid_captcha']);
    }
$GLOBALS['smarty']->assign('rand', mt_rand());

验证码防止灌水刷屏 

if ((intval($_CFG['captcha']) & CAPTCHA_MESSAGE) && gd_version() > 0)
    {
        include_once('includes/cls_captcha.php');
        $validator = new captcha();
        // 验证验证码是否正确 
        if (!$validator->check_word($_POST['captcha']))
        {
            show_message($_LANG['invalid_captcha']);
        }
    }
    else
    {
        //没有验证码时,用时间来限制机器人发帖或恶意发评论 
        if (!isset($_SESSION['send_time']))
        {
            $_SESSION['send_time'] = 0;
        }

        $cur_time = gmtime();
        if (($cur_time - $_SESSION['send_time']) < 30) // 小于30秒禁止发评论
        {
            show_message($_LANG['cmt_spam_warning']);
        }
    }

 

posted @ 2015-01-15 12:14  wpindesign  阅读(1449)  评论(0编辑  收藏  举报