PHP Ajax 验证码(Securimage)问题

发布于 2024-08-24 05:11:09 字数 3657 浏览 1 评论 0原文

我在使用 php 和 ajax 进行验证码验证时遇到了一些问题。 这是 php 验证:

if(trim($code) == '') {
$error_captcha = '<p class="error">some empty error....</p>';
$errorc = 'error';
$error = $erdiv;
 } else if (trim($code) != ''){
require_once ('securimage.php');
$captcha = new Securimage();
$valid = $captcha->check($code);
if ($valid == false) {
echo '<p class="error">some captcha incorrect error...</p>';
$error_captcha .= '<p class="error"></p>';
   }
  }

这是我的表单:(

<form class="wufoo leftLabel page" action="javascript:send_action('register.php',3)">

<div class="info">
 <h2>פזור - טופס רישום</h2>
 <?php echo $error; ?>
</div>

<ul>    

<li class="right <?php echo $erroru; ?>">
 <div class="col">
  <input type="text" class="field text large" id="user_register" value="<?php echo $username; ?>" maxlength="255" />
  <?php echo $error_user; ?>
   </div>
    <label class="desc">
  <span class="req">*</span>
    <?php small('שם משתמש'); ?>
   </label>
  <p class="instruct"><small>שם המשתמש</small></p>
 </li>

<li class="right <?php echo $errorp; ?>">
 <div class="col">
  <input type="password" class="field text large" id="pass_register" value="<?php echo $pass; ?>" maxlength="255" />
  <?php echo $error_pass; ?>
   </div>
    <label class="desc">
        <span class="req">*</span>
  <?php small('סיסמא'); ?>
   </label>
  <p class="instruct"><small>נא הזן את סיסמתך</small></p>
 </li>


<li class="right <?php echo $errorp.''.$errorpv; ?>">
 <div class="col">
  <input type="password" class="field text large" id="pass_val_register" value="<?php echo $pass_val; ?>" maxlength="255" />
  <?php echo $error_pass_val.''.$error_pass; ?>
   </div>
      <label class="desc">
  <span class="req">*</span>
    <?php small('אימות סיסמא'); ?>
   </label> 
  <p class="instruct"><small>נא הזן את סיסמתך שנית</small></p>
 </li>

  <li class="right <?php echo $errore; ?>">
 <div class="col">
  <input type="text" class="field text large" id="email_register" value="<?php echo $email; ?>" maxlength="255" />
    <?php echo $error_email; ?>
 </div>
  <label class="desc">
  <span class="req">*</span>
  <?php small('כתובת דוא"ל'); ?>
   </label>
  <p class="instruct"><small>נא הקפד להזין כתובת דוא"ל חוקית על מנת שתוכל להפעיל את חשבונך</small></p>
 </li>
    <li class="right captcha"></li>
   <li class="right <?php echo $errorc; ?>">
 <div class="col">
  <input type="text" class="field text large" id="captcha_register" maxlength="255" />
    <p><img src="securimage_show.php?sid=<?php echo md5(uniqid(time())); ?>"></p> 
    <?php echo $error_captcha; ?> 
 </div>
  <label class="desc">
  <span class="req">*</span>
  <?php small('קוד אבטחה'); ?>
   </label>
  <p class="instruct"><small>נא הזן את קוד האבטחה כפי שמופיע בתמונה</small></p>
 </li>
 <li class="buttons ">
      <input id="saveForm" name="saveForm" class="btTxt submit" type="submit" value="שלח" />


   </li>
</ul>
</form>

那是 thbrew ) 问题是,当输入错误的字符串时,变量 $eror_captcha 根本没有设置。

i have a little problem with captcha validation using php and ajax.
this is the php validation:

if(trim($code) == '') {
$error_captcha = '<p class="error">some empty error....</p>';
$errorc = 'error';
$error = $erdiv;
 } else if (trim($code) != ''){
require_once ('securimage.php');
$captcha = new Securimage();
$valid = $captcha->check($code);
if ($valid == false) {
echo '<p class="error">some captcha incorrect error...</p>';
$error_captcha .= '<p class="error"></p>';
   }
  }

this is my form:

<form class="wufoo leftLabel page" action="javascript:send_action('register.php',3)">

<div class="info">
 <h2>פזור - טופס רישום</h2>
 <?php echo $error; ?>
</div>

<ul>    

<li class="right <?php echo $erroru; ?>">
 <div class="col">
  <input type="text" class="field text large" id="user_register" value="<?php echo $username; ?>" maxlength="255" />
  <?php echo $error_user; ?>
   </div>
    <label class="desc">
  <span class="req">*</span>
    <?php small('שם משתמש'); ?>
   </label>
  <p class="instruct"><small>שם המשתמש</small></p>
 </li>

<li class="right <?php echo $errorp; ?>">
 <div class="col">
  <input type="password" class="field text large" id="pass_register" value="<?php echo $pass; ?>" maxlength="255" />
  <?php echo $error_pass; ?>
   </div>
    <label class="desc">
        <span class="req">*</span>
  <?php small('סיסמא'); ?>
   </label>
  <p class="instruct"><small>נא הזן את סיסמתך</small></p>
 </li>


<li class="right <?php echo $errorp.''.$errorpv; ?>">
 <div class="col">
  <input type="password" class="field text large" id="pass_val_register" value="<?php echo $pass_val; ?>" maxlength="255" />
  <?php echo $error_pass_val.''.$error_pass; ?>
   </div>
      <label class="desc">
  <span class="req">*</span>
    <?php small('אימות סיסמא'); ?>
   </label> 
  <p class="instruct"><small>נא הזן את סיסמתך שנית</small></p>
 </li>

  <li class="right <?php echo $errore; ?>">
 <div class="col">
  <input type="text" class="field text large" id="email_register" value="<?php echo $email; ?>" maxlength="255" />
    <?php echo $error_email; ?>
 </div>
  <label class="desc">
  <span class="req">*</span>
  <?php small('כתובת דוא"ל'); ?>
   </label>
  <p class="instruct"><small>נא הקפד להזין כתובת דוא"ל חוקית על מנת שתוכל להפעיל את חשבונך</small></p>
 </li>
    <li class="right captcha"></li>
   <li class="right <?php echo $errorc; ?>">
 <div class="col">
  <input type="text" class="field text large" id="captcha_register" maxlength="255" />
    <p><img src="securimage_show.php?sid=<?php echo md5(uniqid(time())); ?>"></p> 
    <?php echo $error_captcha; ?> 
 </div>
  <label class="desc">
  <span class="req">*</span>
  <?php small('קוד אבטחה'); ?>
   </label>
  <p class="instruct"><small>נא הזן את קוד האבטחה כפי שמופיע בתמונה</small></p>
 </li>
 <li class="buttons ">
      <input id="saveForm" name="saveForm" class="btTxt submit" type="submit" value="שלח" />


   </li>
</ul>
</form>

(that's thbrew there)
The problem is that the variable $eror_captcha isn't set at all when entering a wrong string.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蝶舞 2024-08-31 05:11:09

JQman,您的代码中有一些问题会导致很难帮助您排除故障。首先是不知道有效的验证码过程是如何工作的。意思是,我们看不到什么 $valid = $captcha->check($code);事实上确实如此。但是假设您的代码实际上会正确设置对有效验证码的引用,并且当用户输入的代码不匹配时它将返回“false”,这里有一些需要检查的事情:

1-当我将其加载到测试中时环境,我无法显示表格。当我删除所有行时,我会得到一个完整的表格并显示错误消息。尝试删除small()行,看看它是否有效。如果是这样,那么small()函数就有问题了。

2-我注意到它正在 wufoo 上运行。我对他们的服务不是很熟悉,但我知道这一点。他们可能会做一些事情导致代码在出现警告/错误时停止。话虽这么说,我注意到如果有人输入无效代码,您会像这样附加 $error_captcha: $error_captcha .= '

'; ... however, $error_captcha is not previously set in the code you show. This will cause a warning in the log. You may want to consider removing the .= and making it =.

除此之外,我没有看到任何其他因素会导致改变您当前得到的结果。

JQman, there are a few things about your code that will make it difficult to help you troubleshoot. The first is not knowing how the valid captcha process works. Meaning, we cannot see what $valid = $captcha->check($code); actually does. But assuming your code will actually set a reference correctly to the valid captch code and that it will return 'false' when the code the person enters does not match, here are a few things to check:

1- When I load this into a test environment, I cannot get the form to show. When I remove all of the lines, I get a complete form and the error message shows. Try removing the small() lines and see if it will work. If so, then there is something wrong with the small() function.

2- I notice this is running on wufoo. I am not extremely familiar with their service but I am aware of it. They may do something to cause the code to halt on warnings/errors. That being said, I notice that if someone enters an invalid code, you append $error_captcha like so: $error_captcha .= '

'; ... however, $error_captcha is not previously set in the code you show. This will cause a warning in the log. You may want to consider removing the .= and making it =.

Other than that, I do not see anything else that would lead to changing the results you are currently getting.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文