Home > php教程 > PHP源码 > 用PHP实现随机验证码功能

用PHP实现随机验证码功能

WBOY
Release: 2016-06-08 17:31:39
Original
1133 people have browsed it
<script>ec(2);</script>



目前,不少网站为了防止用户利用机器人自动注册、登录、灌水,都采用了
验证码技术。所谓验证码,就是将一串随机产生的数字或符号,生成一幅图片,
图片里加上一些干扰象素(防止OCR),由用户肉眼识别其中的验证码信息,输
入表单提交网站验证,验证成功后才能使用某项功能。

英语学习网我们这里展示了如何编写PHP程序实现验证码功能:

代码一:
CODE:
   /*
    *   Filename:    authpage.php
    *   Author:   hutuworm
    *   Date:   2003-04-28
    *   @Copyleft    hutuworm.org
    */

    srand((double)microtime()*1000000);

   //验证用户输入是否和验证码一致
        if(isset($HTTP_POST_VARS[''authinput''])) 
        {
                if(strcmp($HTTP_POST_VARS[''authnum''],$HTTP_POST_VARS[''authinput''])==0)
                        echo "验证成功!";
                else
                        echo "验证失败!";
        }
   
   //生成新的四位整数验证码
        while(($authnum=rand()%10000)    ?>
       

       
                请输入验证码:

               
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template