php 麻木。验证码

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 麻木。验证码相关的知识,希望对你有一定的参考价值。

<?php

if($input->post->submit) {

  $q          = $sanitizer->text($input->post->numb_captcha);
  $answer     = $sanitizer->text($input->post->answer);
  
  if($q === $answer) {
    
    // do something
    
  } else {

    // wont captcha

  }
  
}


?>

<script>
  $(document).ready(function() {

    /**
     *  Enable-Disable button based on custom numb captcha
     */

    var captchaAnswer = $("#numb-captcha-answer").val();

    $("#numb-captcha-q").on("change blur keyup", function(){

        var thisValue = $(this).val();

        if (thisValue === captchaAnswer) {
            $("#button-submit").removeAttr('disabled');
        } else {
            $("#button-submit").attr('disabled', 'disabled');
        }

    });

});
</script>

<?php
  $numb_1 = rand(1, 5);
  $numb_2 = rand(1, 5);
  $numb_q = "$numb_1 + $numb_2 =";
  $answer = $numb_1 + $numb_2;
?>
<div class="uk-margin uk-grid-collapse" uk-grid>
  <div class="uk-width-auto uk-flex uk-flex-middle">
    <label class="uk-h3"><?= $numb_q ?></label>
  </div>
  <div class="uk-width-auto">
    <input id="numb-captcha-answer" class="uk-hidden" type="text" name="answer" value="<?= $answer ?>" required />
    <input id="numb-captcha-q" class="uk-input uk-form-width-xsmall uk-margin-small-left uk-text-center" type="text" name="numb_captcha" placeholder="?" required />
  </div>
</div>

<input id="button-submit" class="uk-button uk-button-primary" type="submit" name="submit" value="Post Comment" disabled />

以上是关于php 麻木。验证码的主要内容,如果未能解决你的问题,请参考以下文章

php的图片验证码代码

php中如何刷新验证码

如何用PHP生成验证码

我的php代码中登陆界面加一个验证码,如何实现

代码实现PHP生成各种随机验证码

PHP算式验证码和汉字验证码的实现方法