六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 27|回复: 0

php ajax 验证图片

[复制链接]

升级  33.33%

26

主题

26

主题

26

主题

秀才

Rank: 2

积分
100
 楼主| 发表于 2013-1-23 02:59:20 | 显示全部楼层 |阅读模式
<div style="font-size: 14px;">CAPTCHA is a simple test to determine if a user is a computer or ahuman. It is used to prevent spam abuse on the websites. So if youuse CAPTCHA on your web site forms, this can help in stopping some botsand making life harder for other bots in accessing or using your forms.
In brief the CAPTCHA protection works by generating a random string,writing it to an image, then storing the string inside of a session orby some other method. This is then checked when the form is submitted.
The goal of this tutorial is to demonstrate how to make your own simple CAPTCHA protection using PHP and AJAX technologies.
This tutorial is very simple, but if you are unfamiliar with PHP andAJAX this is a great place to start. The tutorial consists of a HTMLpage for presenting a simple form that will send the data, a JavaScriptfile for handling the Ajax functionality, and a simple PHP page thatmakes the actual comparison of the what is in the text box compared towhat phrase was stored in the image.
<a name="#front_end" />The AJAX HTML Page (the Front-end)
The front-end of this tutorial is straight forward. We are going tocreate a simple HTML form with a textbox for entering the securitycode, dynamically generated image holding this code, a button forsubmitting, and a DIV that we will display the CAPTCHA test result. Thefollowing example shows how you can do that. Create a new file namedcaptcha_test.htm, and add this code to it.
<div class="plaincode"><form id="frmCaptcha" name="frmCaptcha">
<table>
  <tr>
    <td align="left">
      <label for="captcha">Captcha</label>
    </td>
    <td>
      <input id="txtCaptcha" type="text" name="txtCaptcha" value="" maxlength="10" size="32" />
    </td>
    <td>
      <img id="imgCaptcha" src="create_image.php" />
    </td>
  </tr>
  <tr>
    <td> </td>
    <td>
      <input id="btnCaptcha" type="button" value="Captcha Test" name="btnCaptcha"
           />
    </td>
  </tr>
</table> 

<div id="result"> </div>
</form>
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表